# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
187104 | Akashi | Candies (JOI18_candies) | C++14 | 4 ms | 684 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
int n;
long long a[200005];
int Left[200005], Right[200005];
priority_queue <pair <int, int> > pq;
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n ; ++i){
scanf("%d", &a[i]);
Left[i] = i - 1; Right[i] = i + 1;
pq.push({a[i], i});
}
long long Sol = 0;
for(int i = 1; i <= (n + 1) / 2 ; ++i){
while(!pq.empty() && a[pq.top().second] != pq.top().first) pq.pop();
int pos = pq.top().second;
pq.pop();
Sol += a[pos];
printf("%lld\n", Sol);
int L = Left[pos], R = Right[pos];
Left[pos] = Left[L]; Right[pos] = Right[R];
Right[Left[L]] = pos; Left[Right[R]] = pos;
a[pos] = max(a[L] + a[R] - a[pos], -INF);
a[L] = a[R] = -INF;
pq.push({a[pos], pos});
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |