给点思路呗~

(⊙o⊙)…,话说你这个思路A了么

1 个赞

mei…有点难受

1 个赞

还是用老师的思路吧

1 个赞

老师的思路我阳历都美国

1 个赞

没太听懂

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node{
    ll x, step;
};
bool operator <(node c, node b){
    if(c.x!=b.x) return c.x<b.x;
    else return c.step<b.step;
}
priority_queue<node> q;
ll a[200005], s[200005];
int main(){
    ll n, ans=-1, m;
    cin >> n >> m;
    for(ll i=0;i<n;i++){
        cin >> a[i];
        s[i]=s[i-1]+a[i];
    }
    q.push(node{s[0], 0});
    for(ll i=1;i<n;i++){
        if(abs(i-q.top().step)<=m){
            ans=max(s[i]-q.top().x, ans);
        }
        q.push(node{s[i], i});
    }
    cout << ans;
}
1 个赞

我也是qwq,不过你应该新建一个贴

1 个赞