注意使用尺取前缀和的时候,一般是连续的和

#include <bits/stdc++.h>
using namespace std;
int a[100001];
int f[100001];
int main()
{
    int n, s;
    cin >> n >> s;
    int ans = n;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        f[i] = f[i - 1] + a[i];
    }
    if (f[n] < s)
        cout << "0";
    else
    {
        int i = 1;
        int j = 0;
        while (i <= n)
        {
            int r = f[i] - f[j];
            if (r < s)
                i++;
            if (r >= s)
            {
                ans = min(ans, i - j );
                j++;
            }
        }
        cout << ans;
    }
    return 0;
}