| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 | 
|---|---|---|---|---|---|---|---|
| 1124368 | pndhpndh | Candies (JOI18_candies) | C++20 | 88 ms | 10672 KiB | 
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define task "task"
using namespace std;
const int inf = 1e18;
const int mx = 2e5 + 5;
int n, m;
int a[mx];
int pre[mx], nxt[mx];
bool vs[mx];
int res[mx];
void read(){
    cin >> n;
    for (int i = 1; i <= n; i++){
        cin >> a[i];
        pre[i] = i - 1;
        nxt[i] = i + 1;
    }
    a[0] = a[n + 1] = -inf;
}
void solve(){
    priority_queue<pair<int,int>> pq;
    for (int i = 1; i <= n; i++){
        pq.push({a[i], i});
    }
    int cnt = 0;
    int cur = 0;
    while (!pq.empty() && cnt <= (n + 1)/2){
        int val = pq.top().first, id = pq.top().second;
        pq.pop();
        if (vs[id]) continue;
        cur += val;
        cnt++;
        res[cnt] = cur;
        a[id] = a[pre[id]] + a[nxt[id]] - a[id];
        vs[nxt[id]] = vs[pre[id]] = true;
        pre[id] = pre[pre[id]];
        nxt[id] = nxt[nxt[id]];
        nxt[pre[id]] = pre[nxt[id]] = id;
        pq.push({a[id], id});
    }
    for (int i = 1; i < cnt; i++){
        cout << res[i] << '\n';
    }
}
signed main(){
    cin.tie(0)->sync_with_stdio(0);
    if(fopen(task".inp", "r")){
        freopen(task".inp", "r", stdin);
        freopen(task".out", "w", stdout);
    }
    read();
    solve();
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
| # | Verdict | Execution time | Memory | Grader output | 
|---|---|---|---|---|
| Fetching results... | ||||
