Submission #1087999

# Submission time Handle Problem Language Result Execution time Memory
1087999 2024-09-13T16:41:18 Z TrinhKhanhDung Candies (JOI18_candies) C++14
100 / 100
73 ms 11028 KB
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(x) (int)x.size()
#define ALL(v) v.begin(),v.end()
#define MASK(k) (1LL << (k))
#define BIT(x, i) (((x) >> (i)) & 1)
#define oo (ll)1e18
#define INF (ll)1e9
#define MOD (ll)(1e9 + 7)

using namespace std;

template<class T1, class T2>
    bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}

template<class T1, class T2>
    bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}

template<class T1, class T2>
    void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;}

template<class T1, class T2>
    void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;}

template<class T>
    void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());}

const int MAX = 2e5 + 10;

int N;
ll a[MAX];
int nxt[MAX], prv[MAX], isDel[MAX];
priority_queue<pair<ll, int>> pq;

void solve(){
    cin >> N;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
        pq.push({a[i], i});
        nxt[i] = i + 1;
        prv[i] = i - 1;
    }
    a[0] = a[N + 1] = -oo;
    ll cur = 0;
    for(int i = 1; i <= (N + 1) / 2; i++){
        while(isDel[pq.top().se]) pq.pop();
        int x = pq.top().se; pq.pop();
        cur += a[x];
        a[x] = a[prv[x]] + a[nxt[x]] - a[x];
        pq.push({a[x], x});
        isDel[prv[x]] = isDel[nxt[x]] = true;
        nxt[x] = nxt[nxt[x]];
        prv[x] = prv[prv[x]];
        nxt[prv[x]] = x;
        prv[nxt[x]] = x;

        cout << cur << '\n';
    }
}

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
//    freopen("numtable.inp","r",stdin);
//    freopen("numtable.out","w",stdout);

    solve();

    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 600 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 1 ms 604 KB Output is correct
7 Correct 1 ms 608 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 1 ms 620 KB Output is correct
12 Correct 1 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 1 ms 604 KB Output is correct
15 Correct 1 ms 604 KB Output is correct
16 Correct 1 ms 604 KB Output is correct
17 Correct 1 ms 604 KB Output is correct
18 Correct 1 ms 604 KB Output is correct
19 Correct 1 ms 604 KB Output is correct
20 Correct 1 ms 604 KB Output is correct
21 Correct 73 ms 10808 KB Output is correct
22 Correct 70 ms 10944 KB Output is correct
23 Correct 73 ms 10940 KB Output is correct
24 Correct 56 ms 10696 KB Output is correct
25 Correct 53 ms 10696 KB Output is correct
26 Correct 55 ms 10684 KB Output is correct
27 Correct 62 ms 10912 KB Output is correct
28 Correct 61 ms 10944 KB Output is correct
29 Correct 65 ms 11028 KB Output is correct
30 Correct 61 ms 10940 KB Output is correct
31 Correct 62 ms 10948 KB Output is correct
32 Correct 61 ms 10940 KB Output is correct
33 Correct 62 ms 10692 KB Output is correct
34 Correct 63 ms 10788 KB Output is correct
35 Correct 66 ms 10684 KB Output is correct
36 Correct 67 ms 10996 KB Output is correct
37 Correct 71 ms 10952 KB Output is correct
38 Correct 68 ms 11016 KB Output is correct
39 Correct 53 ms 10692 KB Output is correct
40 Correct 52 ms 10900 KB Output is correct
41 Correct 52 ms 10696 KB Output is correct
42 Correct 60 ms 10920 KB Output is correct
43 Correct 60 ms 10944 KB Output is correct
44 Correct 60 ms 10984 KB Output is correct
45 Correct 61 ms 10924 KB Output is correct
46 Correct 62 ms 10872 KB Output is correct
47 Correct 67 ms 10936 KB Output is correct
48 Correct 64 ms 10684 KB Output is correct
49 Correct 65 ms 10692 KB Output is correct
50 Correct 65 ms 10684 KB Output is correct