172552025-06-08 11:52:31algoproGamecpp17Time limit exceeded 30/1002.584s4404 KiB
// UUID: 95b34b41-9b6e-4792-b18f-80f34f18ceef
#include<bits/stdc++.h>

using namespace std;

long long n,m,k,l,i,j,a,b,res,mx,ans,t,c,d[200005],g[200005],f[200005];
string s;
vector<int>v[100005];

main(){

cin>>n>>m;

for(i=1;i<=n;i++){
    cin>>d[i];
}

for(i=0;i<m;i++){
    cin>>g[i];
}

for(i=0;i<m;i++){
    mx=0;
    for(j=1;j<=g[i];j++){
        f[d[j]]++;
        mx=max(mx,d[j]);
    }
    a=mx;b=0;
    f[mx]--;
                while(f[mx]==0 && mx>0){
                mx--;
            }
    for(j=g[i]+1;j<=n+g[i];j++){
        if(d[j]>=mx)
            if(j%2==g[i]%2) a+=d[j]; else b+=d[j];
        else
        {
            f[d[j]]++;
            while(f[mx]==0 && mx>0){
                mx--;
            }
            f[mx]--;
            if(j%2==g[i]%2) a+=mx; else b+=mx;
        }
    }
    cout<<a-b<<endl;
}

}

SubtaskSumTestVerdictTimeMemory
subtask110/10
1Accepted3ms2612 KiB
2Accepted3ms2616 KiB
subtask220/20
1Accepted3ms2612 KiB
2Accepted3ms2824 KiB
3Accepted6ms2612 KiB
4Accepted8ms2760 KiB
subtask30/70
1Accepted43ms2612 KiB
2Accepted46ms2612 KiB
3Accepted138ms2920 KiB
4Accepted164ms3052 KiB
5Accepted617ms3636 KiB
6Accepted1.217s3380 KiB
7Accepted846ms3528 KiB
8Accepted862ms3380 KiB
9Accepted1.164s4148 KiB
10Accepted1.592s4148 KiB
11Accepted1.284s3580 KiB
12Time limit exceeded2.582s4404 KiB
13Accepted1.84s4148 KiB
14Time limit exceeded2.584s4360 KiB