记录编号 588518 评测结果 AAAAAAAAAA
题目名称 [POJ 3061]子段和问题 最终得分 100
用户昵称 Gravatar┭┮﹏┭┮ 是否通过 通过
代码语言 C++ 运行时间 0.161 s
提交时间 2024-06-04 15:07:38 内存使用 3.90 MiB
显示代码纯文本
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define F(i,a,b) for(int i = a;i <= b;i++)
#define D(i,a,b) for(int i = a;i >= b;i--)
#define fi first
#define se second
#define pii pair<int,int>
#define pb(x) push_back(x)
const int N = 1e5+10,M = 1e6+10;
const ll inf = 1e17,mod = 998244353;

ll read(){
    ll x = 0,f = 1;char c = getchar();
    for(;c < '0' || c > '9';c = getchar())if(c == '-')f = -1;
    for(;c >= '0' && c <= '9';c = getchar())x = (x<<3) + (x<<1) + c-'0';
    return x * f;
}

int t,n;
ll a[N],m;
int main(){
    freopen("subsequence.in","r",stdin);
    freopen("subsequence.out","w",stdout);
    t = read();
    while(t--){
        ll sum = 0,ans = inf;
        n = read(),m = read();
        memset(a,0,sizeof a);
        F(i,1,n)a[i] = read();
        for(int l = 1,r = 0;l <= n;l++){
            while(sum < m && r <= n)sum += a[++r];
            if(sum >= m)ans = min(ans,(long long)r-l+1);
            sum -= a[l];
        }
        if(ans == inf)printf("0\n");
        else printf("%lld\n",ans);
    }

    return cerr<<endl<<"Time:"<<clock()<<"ms"<<endl,0;

}