参考链接
感觉好像就是双指针啊
#include <bits/stdc++.h>
using namespace std;
int i, j, n;
int a[200];
int sum, m, ans;
int main(){
cin >> n >> m;
for(int i = 0;i < n;i ++ ) cin >> a[i];
i = j = sum = 0;
ans = n;
for(j = 0;j < n;j ++ ){
sum += a[j];
while(sum >= m) sum -= a[i ++ ];
ans = min(ans, j - i + 1);
}
cout << ans;
return 0;
}