# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
47913 | Just_Solve_The_Problem | Candies (JOI18_candies) | C++11 | 141 ms | 65096 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define pii pair < ll, ll >
#define fr first
#define sc second
#define mk make_pair
#define ll long long
const ll inf = (ll)1e15 + 7;
const int N = (int)2e5 + 7;
int n;
priority_queue < pii > q;
ll a[N];
int prv[N], nxt[N];
main() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
scanf("%lld", &a[i]);
q.emplace(mk(a[i], i));
if (i > 1)
prv[i] = i - 1;
if (i < n)
nxt[i] = i + 1;
}
ll ans = 0;
for (int j = 1; j <= (n + 1) / 2; j++) {
while (q.top().fr != a[q.top().sc]) q.pop();
int i = q.top().sc;
ans += q.top().fr;
printf("%lld\n", ans);
int l = prv[i];
int r = nxt[i];
nxt[i] = nxt[r];
prv[i] = prv[l];
nxt[prv[l]] = i;
prv[nxt[r]] = i;
if (l && r) {
a[i] = max(a[l] + a[r] - a[i], -inf);
} else {
a[i] = -inf;
}
a[l] = a[r] = -inf;
q.emplace(mk(a[i], i));
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |