#include<bits/stdc++.h>
#define endl '\n'
#define fi first
#define se second
using namespace std;
const int MAXN=2e5+5;
int n;
long long a[MAXN];
int l[MAXN], r[MAXN];
priority_queue<pair<long long,int> > pq;
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n;
for(int i=1;i<=n;i++) cin>>a[i];
for(int i=1;i<=n;i++)
{
l[i]=r[i]=i;
pq.push({a[i],i});
}
long long ans=0;
for(int i=1;i<=(n+1)/2;i++)
{
auto cur=pq.top();
pq.pop();
if(a[cur.se]!=cur.fi) {i--; continue;}
int le=l[cur.se]-1;
int ri=r[cur.se]+1;
ans+=cur.fi;
cout<<ans<<endl;
l[le]=l[ri]=le;
r[le]=r[ri]=ri;
a[le]=a[ri]=-cur.fi+a[le]+a[ri];
pq.push({a[le],le});
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
536 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |