// High above the clouds there is a rainbow...
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define sz(s) int((s).size())
#define bit(n,k) (((n)>>(k))&1)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int maxn=1e5+10,mod=1e9+7;
const ll inf=1e18;
int a[maxn];
set<pair<ll,pii> >st1;
set<pair<pii,ll> >st2;
ll ans;
int main(){
ios_base::sync_with_stdio(false);cin.tie(0);
int n; cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
st1.insert({a[i],{i,i}});
st2.insert({{i,i},a[i]});
}
for(int _=0; _<(n+1)/2; _++){
auto xx= *st1.rbegin();
ans+= xx.F;
cout<<ans<<"\n";
pair<pii,ll> x= {xx.S,xx.F};
auto it=st2.find(x);
x.S*=-1;
if(it!=st2.begin()){
x.S+= prev(it)->S;
x.F.F= prev(it)->F.F;
st1.erase( {prev(it)->S, prev(it)->F} );
st2.erase(prev(it));
}
if(next(it)!=st2.end()){
x.S+= next(it)->S;
x.F.S= next(it)->F.S;
st1.erase( {next(it)->S, next(it)->F} );
st2.erase(next(it));
}
st1.erase(xx);
st2.erase(it);
st1.insert( {x.S,x.F} );
st2.insert( x );
}
return 0;
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.
// * Overflows.
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
4 ms |
640 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |