Submission #506021

# Submission time Handle Problem Language Result Execution time Memory
506021 2022-01-11T11:57:03 Z sidon Candies (JOI18_candies) C++17
100 / 100
198 ms 11312 KB
#include <bits/stdc++.h>
using namespace std;
#define Z 200'002

int64_t N, K, L[Z], R[Z], r[Z], A[Z], sum;
priority_queue<array<int64_t, 2>> pq;

int main() {
	cin >> N;

	for(int i = 1; i <= N; i++) {
		cin >> A[i];
		L[i] = i - 1, R[i] = i + 1;
		pq.push({A[i], i});
	}
 
	R[N+1] = N+1, L[N+1] = N;
	R[0] = r[0] = r[N+1] = 1;
 
	for(int k = 1; k*2 <= N+1; k++) {
		while(r[pq.top()[1]]) pq.pop();
		auto [v, i] = pq.top(); pq.pop();
 
		cout << (sum += v) << '\n';
		r[L[i]] ? r[i]++ : v -= A[L[i]], r[L[i]]++, R[L[i] = L[L[i]]] = i;
		r[R[i]] ? r[i]++ : v -= A[R[i]], r[R[i]]++, L[R[i] = R[R[i]]] = i;

		if(!r[i]) pq.push({A[i] = -v, i});
	}
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 460 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 2 ms 460 KB Output is correct
4 Correct 2 ms 460 KB Output is correct
5 Correct 2 ms 332 KB Output is correct
6 Correct 1 ms 460 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 2 ms 460 KB Output is correct
15 Correct 2 ms 460 KB Output is correct
16 Correct 2 ms 460 KB Output is correct
17 Correct 1 ms 460 KB Output is correct
18 Correct 2 ms 460 KB Output is correct
19 Correct 1 ms 460 KB Output is correct
20 Correct 2 ms 332 KB Output is correct
21 Correct 160 ms 11260 KB Output is correct
22 Correct 181 ms 11276 KB Output is correct
23 Correct 162 ms 11200 KB Output is correct
24 Correct 130 ms 11280 KB Output is correct
25 Correct 130 ms 11208 KB Output is correct
26 Correct 122 ms 11240 KB Output is correct
27 Correct 157 ms 11208 KB Output is correct
28 Correct 140 ms 11252 KB Output is correct
29 Correct 137 ms 11272 KB Output is correct
30 Correct 142 ms 11188 KB Output is correct
31 Correct 198 ms 11272 KB Output is correct
32 Correct 135 ms 11168 KB Output is correct
33 Correct 137 ms 11224 KB Output is correct
34 Correct 137 ms 11312 KB Output is correct
35 Correct 136 ms 11236 KB Output is correct
36 Correct 170 ms 11180 KB Output is correct
37 Correct 182 ms 11296 KB Output is correct
38 Correct 161 ms 11300 KB Output is correct
39 Correct 143 ms 11280 KB Output is correct
40 Correct 123 ms 11168 KB Output is correct
41 Correct 127 ms 11296 KB Output is correct
42 Correct 146 ms 11160 KB Output is correct
43 Correct 150 ms 11176 KB Output is correct
44 Correct 135 ms 11204 KB Output is correct
45 Correct 145 ms 11284 KB Output is correct
46 Correct 137 ms 11204 KB Output is correct
47 Correct 136 ms 11240 KB Output is correct
48 Correct 142 ms 11296 KB Output is correct
49 Correct 150 ms 11180 KB Output is correct
50 Correct 148 ms 11176 KB Output is correct