Submission #48559

# Submission time Handle Problem Language Result Execution time Memory
48559 2018-05-16T10:59:51 Z ngkan146 Candies (JOI18_candies) C++11
100 / 100
562 ms 19504 KB
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, a[200005];
typedef pair<int,int> ii;
typedef pair<ll,ii> Iii;
typedef pair<int,Iii> iIii;
priority_queue <Iii> q;
set <Iii> pq;
Iii bounded[200005];

int main(){
    iostream::sync_with_stdio(0);
    cin >> n;
    for(int i=1;i<=n;i++){
        cin >> a[i];
        pq.insert(Iii(a[i], ii(i, i)));
        bounded[i] = Iii(a[i], ii(i, i));
    }
    ll summ = 0;
    int boundL = 1;
    int boundR = n;

    for(int _=1;_<=(n+1)/2;_++){
        Iii best;
        while(1){
            best = *pq.rbegin();
            pq.erase(best);
            if (best.second.first < boundL || boundR < best.second.second) continue;
            break;
        }

        summ += best.first;
        Iii tmp = Iii(-best.first, ii(best.second.first-1,best.second.second+1));
        //cout << best.second.first << ' ' << best.second.second << endl;
        //cout << boundL << ' ' << boundR << endl;
        if (tmp.second.first > 0){
            pq.erase(bounded[tmp.second.first]);
            tmp.first += bounded[tmp.second.first].first;
            tmp.second.first = bounded[tmp.second.first].second.first;
        }
        if (tmp.second.second <=n){
            pq.erase(bounded[tmp.second.second]);
            tmp.first += bounded[tmp.second.second].first;
            tmp.second.second = bounded[tmp.second.second].second.second;
        }

        if (tmp.second.first > 0)  bounded[tmp.second.first] = tmp;
        if (tmp.second.second <= n)bounded[tmp.second.second] = tmp;

        cout << summ << '\n';
        if (best.second.first == boundL){
            boundL = best.second.second+2;
            continue;
        }
        if (best.second.second == boundR){
            boundR = best.second.first-2;
            continue;
        }
        pq.insert(tmp);

    }
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 612 KB Output is correct
5 Correct 3 ms 680 KB Output is correct
6 Correct 3 ms 680 KB Output is correct
7 Correct 3 ms 748 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 3 ms 912 KB Output is correct
12 Correct 3 ms 912 KB Output is correct
13 Correct 3 ms 912 KB Output is correct
14 Correct 3 ms 912 KB Output is correct
15 Correct 3 ms 912 KB Output is correct
16 Correct 3 ms 912 KB Output is correct
17 Correct 3 ms 912 KB Output is correct
18 Correct 3 ms 912 KB Output is correct
19 Correct 3 ms 912 KB Output is correct
20 Correct 3 ms 912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 504 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 612 KB Output is correct
4 Correct 3 ms 612 KB Output is correct
5 Correct 3 ms 680 KB Output is correct
6 Correct 3 ms 680 KB Output is correct
7 Correct 3 ms 748 KB Output is correct
8 Correct 3 ms 748 KB Output is correct
9 Correct 3 ms 748 KB Output is correct
10 Correct 3 ms 852 KB Output is correct
11 Correct 3 ms 912 KB Output is correct
12 Correct 3 ms 912 KB Output is correct
13 Correct 3 ms 912 KB Output is correct
14 Correct 3 ms 912 KB Output is correct
15 Correct 3 ms 912 KB Output is correct
16 Correct 3 ms 912 KB Output is correct
17 Correct 3 ms 912 KB Output is correct
18 Correct 3 ms 912 KB Output is correct
19 Correct 3 ms 912 KB Output is correct
20 Correct 3 ms 912 KB Output is correct
21 Correct 446 ms 19308 KB Output is correct
22 Correct 465 ms 19312 KB Output is correct
23 Correct 453 ms 19312 KB Output is correct
24 Correct 177 ms 19312 KB Output is correct
25 Correct 187 ms 19312 KB Output is correct
26 Correct 178 ms 19312 KB Output is correct
27 Correct 188 ms 19364 KB Output is correct
28 Correct 189 ms 19364 KB Output is correct
29 Correct 190 ms 19372 KB Output is correct
30 Correct 207 ms 19472 KB Output is correct
31 Correct 210 ms 19472 KB Output is correct
32 Correct 203 ms 19472 KB Output is correct
33 Correct 306 ms 19472 KB Output is correct
34 Correct 286 ms 19472 KB Output is correct
35 Correct 293 ms 19472 KB Output is correct
36 Correct 458 ms 19472 KB Output is correct
37 Correct 562 ms 19472 KB Output is correct
38 Correct 537 ms 19504 KB Output is correct
39 Correct 221 ms 19504 KB Output is correct
40 Correct 189 ms 19504 KB Output is correct
41 Correct 193 ms 19504 KB Output is correct
42 Correct 208 ms 19504 KB Output is correct
43 Correct 190 ms 19504 KB Output is correct
44 Correct 201 ms 19504 KB Output is correct
45 Correct 218 ms 19504 KB Output is correct
46 Correct 204 ms 19504 KB Output is correct
47 Correct 231 ms 19504 KB Output is correct
48 Correct 298 ms 19504 KB Output is correct
49 Correct 294 ms 19504 KB Output is correct
50 Correct 292 ms 19504 KB Output is correct