#include <bits/stdc++.h>
using namespace std;
#define finish(x) return cout << x << endl, 0
#define ll long long
int n;
vector <ll> a;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
a.resize(n);
for(auto &i : a) cin >> i;
set <int> alive;
set <pair <ll, int> > s;
for(int i = 0 ; i < n ; i++){
alive.insert(i);
s.insert(make_pair(a[i], i));
}
ll ans = 0;
for(int itt = 0 ; itt < (n + 1) / 2 ; itt++){
auto top = *--s.end();
s.erase(--s.end());
ans += top.first;
cout << ans << endl;
int pos = top.second;
alive.erase(pos);
a[pos] *= -1;
auto it = alive.upper_bound(pos);
if(it != alive.end()){
a[pos] += a[*it];
s.erase(make_pair(a[*it], *it));
alive.erase(*it);
}
it = alive.upper_bound(pos);
if(it != alive.begin()){
it--;
a[pos] += a[*it];
s.erase(make_pair(a[*it], *it));
alive.erase(*it);
}
alive.insert(pos);
s.insert(make_pair(a[pos], pos));
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
7 ms |
504 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |