제출 #95338

#제출 시각아이디문제언어결과실행 시간메모리
95338dalgerokCandies (JOI18_candies)C++14
100 / 100
673 ms27512 KiB
#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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...