#include<bits/stdc++.h>
using namespace std;
#define endl "\n";
#define int long long
int t, n, s, a[300005], sum, j, ans = 1e18;
void calc()
{
bool f = 0;
cin >> n >> s;
for(int i = 1; i <= n; i++)
cin >> a[i];
ans = 1e18;
sum = a[1];
j = 1;
for(int i = 1; i <= n; i++)
{
sum -= a[i - 1];
while(sum < s)
{
j++;
sum += a[j];
if(j > n)
{
f = 1;
break;
}
}
if(f)
break;
ans = min(ans, j - i + 1);
}
if(ans == 0)
ans = 1;
if(ans == 1e18)
ans = 0;
cout << ans << endl;
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> t;
while(t--)
calc();
return 0;
}
1 个赞
1e18是double类型,可能会错
1 个赞
没有报错
没有考虑s=0的情况
为什么ans=0就要改成1
谢谢!!!!!!!
我过了,此贴结