#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
#define int long long
#define ull unsigned long long
#define F(j,i,n) for(int i = j;i <= n;i++)
#define F_(j,i,n) for(int i = j;i >= n;i--)
const int N = 3e5 + 50;
const int M = 1e3 + 50;
const int INF = 0x3f3f3f3f3f3f3f3f;
const int INT = 0x7fffffff;
const int mod = 1e9 + 7;
void read(int &x){
int f = 1;
x = 0;
char s = getchar();
while(s < '0' || s > '9') {
if(s == '-') f = -1;
s = getchar();
}
while(s >= '0' && s <= '9') {
x = x * 10 + s - '0';
s = getchar();
}
x *= f;
}
void write(int x){
if(x < 0){
putchar('-');
x = -x;
}
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
return;
}
int n,s,t;
int a[N],res[N];
int ans = INF;
signed main(){
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
read(t);
while(t --){
read(n),read(s);
if(s == 0){
printf("1\n");
continue;
}
ans = INF;
F(1,i,n){
read(a[i]);
res[i] = res[i - 1] + a[i];
}
if(res[n] < s){
printf("0\n");
continue;
}
for(int i = 1,j = 1;j <= n;i ++){
while(res[j] - res[i - 1] < s && j <= n) j++;
if(res[j] - res[i - 1] >= s) ans = min(ans,(j-i>=0?j - i + 1:1));
}
if(ans == 0){
printf("1\n");
continue;
}
write(ans);
printf("\n");
}
// fclose(stdin);
// fclose(stdout);
return 0;
}
请发题面
2 个赞
题目描述:
给定一个含有 �n 个整数的数组和一个整数 �s ,找出该数组中满足其和 ≥�≥s 的长度最小的连续子数组。
如果不存在符合条件的连续子数组,输出 00。
输入格式:
第一行包含一个整数 �T,表示测试数据组数。
对于每组测试数据,
第一行包含两个整数 �n, �s。
接下来包含 �n 个整数 ��ai
输出格式:
对于每组测试数据,输出一个整数表示答案。
2 个赞
题目标题是什么?
2 个赞
第几课
3 个赞
你发的是比赛,我们进不去
3 个赞
额…好吧
3 个赞
所以,题目呢?
4 个赞
可以截图吗?
4 个赞