Submission #202256

# Submission time Handle Problem Language Result Execution time Memory
202256 2020-02-14T15:09:27 Z quocnguyen1012 Candies (JOI18_candies) C++14
100 / 100
141 ms 10288 KB
#include <bits/stdc++.h>
using namespace std;
 
const long long INF = 1e18;
 
int n;
long long a[200005];
int Left[200005], Right[200005];
priority_queue <pair <long long, int> > pq;
 
int main()
{
    scanf("%d", &n);
 
    for(int i = 1; i <= n ; ++i){
        scanf("%lld", &a[i]);
        Left[i] = i - 1; Right[i] = i + 1;
        pq.push({a[i], i});
    }
 
    a[0] = a[n + 1] = -INF;
    long long Sol = 0;
    for(int i = 1; i <= (n + 1) / 2 ; ++i){
        while(!pq.empty() && a[pq.top().second] != pq.top().first) pq.pop();
        int pos = pq.top().second;
        pq.pop();
        Sol += a[pos];
        printf("%lld\n", Sol);
 
        int L = Left[pos], R = Right[pos];
        Left[pos] = Left[L]; Right[pos] = Right[R];
        Right[Left[L]] = pos; Left[Right[R]] = pos;
 
        a[pos] = max(a[L] + a[R] - a[pos], -INF);
        a[L] = a[R] = -INF;
        pq.push({a[pos], pos});
    }
 
    return 0;
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:13:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d", &n);
     ~~~~~^~~~~~~~~~
candies.cpp:16:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%lld", &a[i]);
         ~~~~~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 376 KB Output is correct
2 Correct 6 ms 504 KB Output is correct
3 Correct 6 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 6 ms 504 KB Output is correct
6 Correct 6 ms 504 KB Output is correct
7 Correct 6 ms 504 KB Output is correct
8 Correct 6 ms 504 KB Output is correct
9 Correct 6 ms 376 KB Output is correct
10 Correct 6 ms 504 KB Output is correct
11 Correct 6 ms 504 KB Output is correct
12 Correct 6 ms 504 KB Output is correct
13 Correct 6 ms 504 KB Output is correct
14 Correct 6 ms 504 KB Output is correct
15 Correct 6 ms 504 KB Output is correct
16 Correct 6 ms 424 KB Output is correct
17 Correct 6 ms 504 KB Output is correct
18 Correct 6 ms 504 KB Output is correct
19 Correct 6 ms 504 KB Output is correct
20 Correct 6 ms 504 KB Output is correct
21 Correct 141 ms 10148 KB Output is correct
22 Correct 139 ms 10076 KB Output is correct
23 Correct 136 ms 10076 KB Output is correct
24 Correct 102 ms 9992 KB Output is correct
25 Correct 105 ms 10076 KB Output is correct
26 Correct 101 ms 9948 KB Output is correct
27 Correct 107 ms 10204 KB Output is correct
28 Correct 110 ms 10204 KB Output is correct
29 Correct 108 ms 10208 KB Output is correct
30 Correct 110 ms 10208 KB Output is correct
31 Correct 114 ms 10288 KB Output is correct
32 Correct 115 ms 10204 KB Output is correct
33 Correct 117 ms 9948 KB Output is correct
34 Correct 123 ms 10004 KB Output is correct
35 Correct 123 ms 9948 KB Output is correct
36 Correct 140 ms 10152 KB Output is correct
37 Correct 138 ms 10080 KB Output is correct
38 Correct 139 ms 10148 KB Output is correct
39 Correct 98 ms 9948 KB Output is correct
40 Correct 106 ms 10088 KB Output is correct
41 Correct 99 ms 9948 KB Output is correct
42 Correct 107 ms 10204 KB Output is correct
43 Correct 105 ms 10204 KB Output is correct
44 Correct 106 ms 10204 KB Output is correct
45 Correct 116 ms 10204 KB Output is correct
46 Correct 107 ms 10204 KB Output is correct
47 Correct 110 ms 10204 KB Output is correct
48 Correct 122 ms 10076 KB Output is correct
49 Correct 123 ms 9992 KB Output is correct
50 Correct 117 ms 9948 KB Output is correct