day2: 差点忘记今天的每日一题了

滑动窗口,如果窗口内值<x就继续扩展窗口,记录最小窗口即可

#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long LL;
typedef long long ll;
typedef pair<int,int> PII;


const int INF = 0x3f3f3f3f;


void debug()
{
     cout<<"debug"<<endl;
}


class solution
{
    public:
        void solve();
        void ycl();
        solution(){};
};


LL power(LL a,LL b,LL p) { 
    int res = 1;
    for (; b; b /= 2, a = 1LL * a * a % p) {
        if (b % 2) {
            res = 1LL * res * a % p;
        }
    }
    return res;
}

const int mod = 998244353;

void solution::solve()
{
    int n,x;cin>>n>>x;
    vector<int>a(n+1);
    for(int i=1;i<=n;i++)cin>>a[i];
    int sum = a[1];
    PII ans;
    int mi = INF;
    for(int l=1,r=1;l<=n&&r<=n;)
    {
        while(r<=n&&sum<x)sum += a[++r];
        if(r-l+1<mi)
        {
            mi = r-l+1;
            ans = {l,r};
        }
        sum -= a[l];
        l ++;
    }
    auto [l,r]=ans;
    cout<<l<<' '<<r<<endl;
}


signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
    int T = 1;
    solution AC;
    //cin>>T;
    //AC.ycl();
    while(T --)
    {
        AC.solve();
    }
    return 0;
}