# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
868409 | mgl_diamond | Candies (JOI18_candies) | C++17 | 83 ms | 14232 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
#define foru(i, l, r) for(int i=(l); i<=(r); ++i)
#define ford(i, l, r) for(int i=(l); i>=(r); --i)
#define fore(x, v) for(auto &x : v)
#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()
#define fi first
#define se second
#define file "input"
void setIO() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
if (fopen(file".inp", "r")) {
freopen(file".inp", "r", stdin);
freopen(file".out", "w", stdout);
}
}
const ll INF = 1e18;
const int N = 2e5+5;
ll n, a[N], l[N], r[N], del[N];
priority_queue<pair<ll, ll>> pq;
int main() {
setIO();
cin >> n;
foru(i, 1, n) {
cin >> a[i];
pq.push({a[i], i});
l[i] = i-1;
r[i] = i+1;
}
a[0] = a[n+1] = -INF;
ll ans = 0;
foru(z, 1, (n+1) >> 1) {
while (del[pq.top().se]) pq.pop();
auto [val, i] = pq.top();
pq.pop();
ans += val;
cout << ans << "\n";
a[i] = a[l[i]] + a[r[i]] - a[i];
pq.push({a[i], i});
del[l[i]] = del[r[i]] = 1;
r[l[l[i]]] = i;
l[r[r[i]]] = i;
l[i] = l[l[i]];
r[i] = r[r[i]];
}
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |