Submission #47325

# Submission time Handle Problem Language Result Execution time Memory
47325 2018-05-01T03:19:43 Z szawinis Candies (JOI18_candies) C++17
100 / 100
190 ms 66832 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 2e5+1;
const ll INF = 1e17;

int n;
ll a[N], pre[N], nxt[N];
priority_queue<pair<ll, int> > pq;
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> a[i];
		if(i > 1) pre[i] = i-1;
		if(i < n) nxt[i] = i+1;
		pq.emplace(a[i], i);
	}
	ll ans = 0;
	for(int z = 1; z <= n+1 >> 1; z++) {
		while(pq.top().first != a[pq.top().second]) pq.pop();
		int i = pq.top().second;
		ans += a[i];
		cout << ans << '\n';
		int l = pre[i], r = nxt[i];
		nxt[i] = nxt[r];
		pre[i] = pre[l];
		pre[nxt[r]] = i;
		nxt[pre[l]] = i;
		if(l && r) a[i] = max(a[l] + a[r] - a[i], -INF);
      	else a[i] = -INF;
		a[l] = a[r] = -INF;
		pq.emplace(a[i], i);
	}
}

Compilation message

candies.cpp: In function 'int main()':
candies.cpp:22:23: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
  for(int z = 1; z <= n+1 >> 1; z++) {
                      ~^~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 708 KB Output is correct
4 Correct 3 ms 708 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 3 ms 924 KB Output is correct
7 Correct 3 ms 924 KB Output is correct
8 Correct 3 ms 924 KB Output is correct
9 Correct 4 ms 988 KB Output is correct
10 Correct 3 ms 1008 KB Output is correct
11 Correct 3 ms 1028 KB Output is correct
12 Correct 3 ms 1048 KB Output is correct
13 Correct 3 ms 1068 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1128 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 3 ms 1200 KB Output is correct
18 Correct 3 ms 1224 KB Output is correct
19 Correct 3 ms 1224 KB Output is correct
20 Correct 3 ms 1228 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 3 ms 612 KB Output is correct
3 Correct 3 ms 708 KB Output is correct
4 Correct 3 ms 708 KB Output is correct
5 Correct 3 ms 708 KB Output is correct
6 Correct 3 ms 924 KB Output is correct
7 Correct 3 ms 924 KB Output is correct
8 Correct 3 ms 924 KB Output is correct
9 Correct 4 ms 988 KB Output is correct
10 Correct 3 ms 1008 KB Output is correct
11 Correct 3 ms 1028 KB Output is correct
12 Correct 3 ms 1048 KB Output is correct
13 Correct 3 ms 1068 KB Output is correct
14 Correct 3 ms 1108 KB Output is correct
15 Correct 3 ms 1128 KB Output is correct
16 Correct 3 ms 1128 KB Output is correct
17 Correct 3 ms 1200 KB Output is correct
18 Correct 3 ms 1224 KB Output is correct
19 Correct 3 ms 1224 KB Output is correct
20 Correct 3 ms 1228 KB Output is correct
21 Correct 148 ms 12448 KB Output is correct
22 Correct 142 ms 14420 KB Output is correct
23 Correct 147 ms 16360 KB Output is correct
24 Correct 102 ms 18176 KB Output is correct
25 Correct 106 ms 19848 KB Output is correct
26 Correct 110 ms 21776 KB Output is correct
27 Correct 156 ms 23668 KB Output is correct
28 Correct 190 ms 25552 KB Output is correct
29 Correct 123 ms 27584 KB Output is correct
30 Correct 133 ms 29576 KB Output is correct
31 Correct 122 ms 31484 KB Output is correct
32 Correct 139 ms 33656 KB Output is correct
33 Correct 121 ms 35308 KB Output is correct
34 Correct 121 ms 36916 KB Output is correct
35 Correct 123 ms 38708 KB Output is correct
36 Correct 151 ms 40564 KB Output is correct
37 Correct 128 ms 42608 KB Output is correct
38 Correct 132 ms 44536 KB Output is correct
39 Correct 103 ms 46384 KB Output is correct
40 Correct 102 ms 48140 KB Output is correct
41 Correct 104 ms 49808 KB Output is correct
42 Correct 119 ms 51980 KB Output is correct
43 Correct 114 ms 53920 KB Output is correct
44 Correct 115 ms 55760 KB Output is correct
45 Correct 117 ms 57732 KB Output is correct
46 Correct 115 ms 59644 KB Output is correct
47 Correct 127 ms 61644 KB Output is correct
48 Correct 123 ms 63340 KB Output is correct
49 Correct 123 ms 65060 KB Output is correct
50 Correct 133 ms 66832 KB Output is correct