// 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=2e5+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;
bool bad=0;
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));
}
else{
bad=1;
}
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));
}
else{
bad=1;
}
st1.erase(xx);
st2.erase(it);
if(bad==0){
st1.insert( {x.S,x.F} );
st2.insert( x );
}
}
return 0;
}
// Deathly mistakes:
// * Read the problem curfully.
// * Check maxn.
// * Overflows.
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
10 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
19 |
Correct |
4 ms |
640 KB |
Output is correct |
20 |
Correct |
4 ms |
640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
640 KB |
Output is correct |
2 |
Correct |
6 ms |
640 KB |
Output is correct |
3 |
Correct |
5 ms |
640 KB |
Output is correct |
4 |
Correct |
5 ms |
640 KB |
Output is correct |
5 |
Correct |
4 ms |
640 KB |
Output is correct |
6 |
Correct |
4 ms |
640 KB |
Output is correct |
7 |
Correct |
4 ms |
640 KB |
Output is correct |
8 |
Correct |
4 ms |
640 KB |
Output is correct |
9 |
Correct |
3 ms |
640 KB |
Output is correct |
10 |
Correct |
4 ms |
640 KB |
Output is correct |
11 |
Correct |
5 ms |
640 KB |
Output is correct |
12 |
Correct |
4 ms |
640 KB |
Output is correct |
13 |
Correct |
1 ms |
640 KB |
Output is correct |
14 |
Correct |
10 ms |
640 KB |
Output is correct |
15 |
Correct |
4 ms |
640 KB |
Output is correct |
16 |
Correct |
5 ms |
640 KB |
Output is correct |
17 |
Correct |
5 ms |
640 KB |
Output is correct |
18 |
Correct |
4 ms |
640 KB |
Output is correct |
19 |
Correct |
4 ms |
640 KB |
Output is correct |
20 |
Correct |
4 ms |
640 KB |
Output is correct |
21 |
Correct |
814 ms |
29660 KB |
Output is correct |
22 |
Correct |
816 ms |
29752 KB |
Output is correct |
23 |
Correct |
799 ms |
29688 KB |
Output is correct |
24 |
Correct |
301 ms |
29432 KB |
Output is correct |
25 |
Correct |
308 ms |
29528 KB |
Output is correct |
26 |
Correct |
313 ms |
29432 KB |
Output is correct |
27 |
Correct |
302 ms |
29692 KB |
Output is correct |
28 |
Correct |
298 ms |
29560 KB |
Output is correct |
29 |
Correct |
297 ms |
29632 KB |
Output is correct |
30 |
Correct |
322 ms |
29688 KB |
Output is correct |
31 |
Correct |
316 ms |
29560 KB |
Output is correct |
32 |
Correct |
326 ms |
29848 KB |
Output is correct |
33 |
Correct |
500 ms |
29532 KB |
Output is correct |
34 |
Correct |
504 ms |
29436 KB |
Output is correct |
35 |
Correct |
536 ms |
29648 KB |
Output is correct |
36 |
Correct |
894 ms |
29800 KB |
Output is correct |
37 |
Correct |
854 ms |
29872 KB |
Output is correct |
38 |
Correct |
835 ms |
29920 KB |
Output is correct |
39 |
Correct |
330 ms |
29680 KB |
Output is correct |
40 |
Correct |
338 ms |
29432 KB |
Output is correct |
41 |
Correct |
331 ms |
29528 KB |
Output is correct |
42 |
Correct |
298 ms |
29736 KB |
Output is correct |
43 |
Correct |
322 ms |
29688 KB |
Output is correct |
44 |
Correct |
328 ms |
29616 KB |
Output is correct |
45 |
Correct |
327 ms |
29632 KB |
Output is correct |
46 |
Correct |
340 ms |
29544 KB |
Output is correct |
47 |
Correct |
362 ms |
29624 KB |
Output is correct |
48 |
Correct |
536 ms |
29432 KB |
Output is correct |
49 |
Correct |
489 ms |
29428 KB |
Output is correct |
50 |
Correct |
463 ms |
29432 KB |
Output is correct |