이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N = 2e5 + 5, INF = 5e18;
int n, a[N], ans;
set < int > alive;
set < pair < int, int > > q;
main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++){
cin >> a[i];
q.insert(make_pair(a[i], i));
}
a[0] = a[n + 1] = -INF;
for(int i = 0; i <= n + 1; i++){
alive.insert(i);
}
for(int i = 1; i <= (n + 1) / 2; i++){
int pos = q.rbegin()->second,
val = q.rbegin()->first;
q.erase(--q.end());
alive.erase(pos);
ans += val;
a[pos] = -a[pos];
auto it = alive.upper_bound(pos);
if(it != alive.end()){
a[pos] += a[*it];
q.erase(make_pair(a[*it], *it));
alive.erase(it);
}
it = alive.upper_bound(pos);
if(it != alive.begin()){
it--;
a[pos] += a[*it];
q.erase(make_pair(a[*it], *it));
alive.erase(it);
}
alive.insert(pos);
q.insert(make_pair(a[pos], pos));
cout << ans << "\n";
}
}
컴파일 시 표준 에러 (stderr) 메시지
candies.cpp:18:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
main(){
^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |