# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
95828 | 2019-02-02T19:07:37 Z | Kastanda | Candies (JOI18_candies) | C++11 | 503 ms | 19600 KB |
#include<bits/stdc++.h> using namespace std; typedef long long ll; const int N = 200005; int n, L[N], R[N]; ll A[N]; set < pair < ll , int > > S; int main() { scanf("%d", &n); for (int i = 1; i <= n; i++) { scanf("%lld", &A[i]); L[i] = i - 1; R[i] = i + 1; S.insert({A[i], i}); } ll Mx = 0; for (int i = 0; i < (n + 1 >> 1); i++) { int id = S.rbegin()->second; S.erase(*S.rbegin()); Mx += A[id]; printf("%lld\n", Mx); int le = L[id], ri = R[id]; S.erase({A[le], le}); S.erase({A[ri], ri}); if (le <= 0 || ri <= 0 || ri > n || le > n) { L[R[ri]] = 0; R[L[le]] = n + 1; continue; } A[id] = A[le] + A[ri] - A[id]; L[id] = L[le]; R[id] = R[ri]; L[R[id]] = id; R[L[id]] = id; S.insert({A[id], id}); } return 0; }
Compilation message
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 508 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 504 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 504 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 504 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 504 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 508 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 3 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 540 KB | Output is correct |
19 | Correct | 3 ms | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
# | 결과 | 실행 시간 | 메모리 | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 508 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 3 ms | 504 KB | Output is correct |
4 | Correct | 3 ms | 504 KB | Output is correct |
5 | Correct | 3 ms | 504 KB | Output is correct |
6 | Correct | 3 ms | 504 KB | Output is correct |
7 | Correct | 3 ms | 504 KB | Output is correct |
8 | Correct | 3 ms | 504 KB | Output is correct |
9 | Correct | 3 ms | 504 KB | Output is correct |
10 | Correct | 3 ms | 504 KB | Output is correct |
11 | Correct | 3 ms | 504 KB | Output is correct |
12 | Correct | 3 ms | 504 KB | Output is correct |
13 | Correct | 3 ms | 504 KB | Output is correct |
14 | Correct | 3 ms | 504 KB | Output is correct |
15 | Correct | 3 ms | 508 KB | Output is correct |
16 | Correct | 3 ms | 504 KB | Output is correct |
17 | Correct | 3 ms | 504 KB | Output is correct |
18 | Correct | 3 ms | 540 KB | Output is correct |
19 | Correct | 3 ms | 504 KB | Output is correct |
20 | Correct | 3 ms | 504 KB | Output is correct |
21 | Correct | 445 ms | 19600 KB | Output is correct |
22 | Correct | 503 ms | 19448 KB | Output is correct |
23 | Correct | 382 ms | 19468 KB | Output is correct |
24 | Correct | 171 ms | 19164 KB | Output is correct |
25 | Correct | 187 ms | 19192 KB | Output is correct |
26 | Correct | 174 ms | 19204 KB | Output is correct |
27 | Correct | 182 ms | 19324 KB | Output is correct |
28 | Correct | 163 ms | 19320 KB | Output is correct |
29 | Correct | 165 ms | 19320 KB | Output is correct |
30 | Correct | 175 ms | 19456 KB | Output is correct |
31 | Correct | 174 ms | 19448 KB | Output is correct |
32 | Correct | 172 ms | 19448 KB | Output is correct |
33 | Correct | 261 ms | 19192 KB | Output is correct |
34 | Correct | 253 ms | 19192 KB | Output is correct |
35 | Correct | 259 ms | 19460 KB | Output is correct |
36 | Correct | 457 ms | 19448 KB | Output is correct |
37 | Correct | 480 ms | 19468 KB | Output is correct |
38 | Correct | 459 ms | 19448 KB | Output is correct |
39 | Correct | 178 ms | 19344 KB | Output is correct |
40 | Correct | 176 ms | 19164 KB | Output is correct |
41 | Correct | 175 ms | 19196 KB | Output is correct |
42 | Correct | 178 ms | 19392 KB | Output is correct |
43 | Correct | 182 ms | 19448 KB | Output is correct |
44 | Correct | 176 ms | 19452 KB | Output is correct |
45 | Correct | 184 ms | 19440 KB | Output is correct |
46 | Correct | 171 ms | 19324 KB | Output is correct |
47 | Correct | 183 ms | 19520 KB | Output is correct |
48 | Correct | 301 ms | 19448 KB | Output is correct |
49 | Correct | 306 ms | 19192 KB | Output is correct |
50 | Correct | 291 ms | 19156 KB | Output is correct |