3 条题解

  • 1
    @ 2024-12-16 21:28:51

    `

    #include<bits/stdc++.h>
    #define int long long
    using namespace std;
    const int inf=0x3f3f3f3f;
    const int f=1e9+7;
    const int N=2e5+10;
    int a[N],b[N];
    void solve()
    {
        int n,x,k;
        cin >> n >> x >> k;
        for(int i=1; i<=n; i++){
            cin >> a[i];
            b[i]=b[i-1]+a[i];
        }
        int s1=0,s2=0,sum=0;
        s1=x;   // 从 1 到 诅咒桃树 的距离 s1
        s2=n-x+1; // 从 诅咒桃树 到 n 的距离 s2
        if(k>=s1){
            sum=max(b[x],sum);
        }else{
            for(int i=1; i<=x; i++){
                if(i+k-1>=x) break;
                sum=max(b[i+k-1]-b[i-1],sum);
            }
        }
    
        if(k>=s2){
            sum=max(b[n]-b[x-1],sum);
        }else{
            for(int i=x; i<=n; i++){
                if(i+k-1>n) break;
                sum=max(b[i+k-1]-b[i-1],sum);
            }
        }
        cout << sum << endl;
    
    }
    void close(){
        ios::sync_with_stdio(false);
        cin.tie(0);
        cout.tie(0);
    }
    signed main ()
    {
        close();int T = 1;
    //    cin >> T;
        while(T--) solve();
        return 0;
    } //
    

    信息

    ID
    1097
    时间
    1000ms
    内存
    256MiB
    难度
    8
    标签
    (无)
    递交数
    298
    已通过
    41
    上传者