我也不知道为什么二分跑得比尺取法还快,这不科学
#include<iostream>
#include<cstdio>
#define rep(i,j,k) for(register int i(j);i<=k;++i)
using std::cin;
using std::cout;
const int N = 1e5 + 79;
int a[N], sum[N], S, n;
inline bool check(int len) {
rep(i, len, n) {
if(sum[i] - sum[i - len] >= S) return true;
}
return false;
}
inline void solve1() {
int ans(0);
int l = 0, r = n;
while(l <= r) {
int mid(l + r >> 1);
if(check(mid)) {
ans = mid;
r = mid - 1;
} else l = mid + 1;
}
cout << ans << '
';
}
inline void solve2() {
int ans(N);
int L(0), R(0),tot(0);
while(1){
while(R<n&&tot<S){
tot+=a[++R];
}
if(tot<S) break;//ºóÃæÈ«¼ÓÉÏҲûÓÃ
ans=std::min(ans,R-L+1);
tot-=a[L++];
}
cout << (ans == N ? 0 : ans) << '
';
}
int main() {
std::ios::sync_with_stdio(false);
int T;
cin >> T;
while(T--) {
cin >> n >> S;
sum[0] = 0;
rep(i, 1, n) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
// solve1();
solve2();
}
return 0;
}