이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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));
}
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |