#include<bits/stdc++.h>
#define MAXN 500007
using namespace std;
const long long inf=1e17;
int n,best;
long long a[MAXN],sum,maxs,curr;
bool used[MAXN];
long long calc(int x){
long long res=a[x];
for(int i=x-1;used[i] and i>=1;i-=2){
res-=a[i]; res+=a[i-1];
}
for(int i=x+1;used[i] and i<=n;i+=2){
res-=a[i]; res+=a[i+1];
}
return res;
}
void mark(int x){
used[x]=true;
for(int i=x-1;used[i] and i>=1;i-=2){
used[i]=false;
used[i-1]=true;
}
for(int i=x+1;used[i] and i<=n;i+=2){
used[i]=false;
used[i+1]=true;
}
}
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n/2+n%2;i++){
maxs=-inf;
for(int f=1;f<=n;f++){
if(used[f])continue;
curr=calc(f);
if(curr>maxs){
maxs=curr; best=f;
}
}
mark(best); sum+=maxs;
cout<<sum<<"\n";
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
13 ms |
2908 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |