# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
293918 | 2020-09-08T13:45:14 Z | sabamaku | Exercise Deadlines (CCO20_day1problem2) | C++14 | 258 ms | 56472 KB |
#include<bits/stdc++.h> using namespace std; int n,d[2000005],p[2000005]; vector <int> mp[2000005]; priority_queue <int> q; int solve(int a){ int x = 0; for(int i = a; i > 0; i -= (i & -i)){ x += p[i]; } return x; } void update(int a){ for(int i = a + 1; i <= n; i += (i & -i)){ p[i]++; } } int a; int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> d[i]; mp[d[i]].push_back(i); } sort(d + 1,d + n + 1); for(int i = 1; i <= n; i++){ if(d[i] < i){ cout << -1; return 0; } } long long ans = 0; for(int i = n; i >= 1; i--){ for(int j = 0; j < mp[i].size(); j++){ q.push(mp[i][j]); } a = q.top(); q.pop(); int x = solve(a); ans += i - (a - x); update(a); } cout << ans; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 47488 KB | Output is correct |
2 | Correct | 37 ms | 47480 KB | Output is correct |
3 | Correct | 36 ms | 47360 KB | Output is correct |
4 | Correct | 36 ms | 47396 KB | Output is correct |
5 | Correct | 36 ms | 47480 KB | Output is correct |
6 | Correct | 38 ms | 47480 KB | Output is correct |
7 | Correct | 36 ms | 47488 KB | Output is correct |
8 | Correct | 36 ms | 47488 KB | Output is correct |
9 | Correct | 36 ms | 47480 KB | Output is correct |
10 | Correct | 35 ms | 47488 KB | Output is correct |
11 | Correct | 36 ms | 47488 KB | Output is correct |
12 | Correct | 35 ms | 47488 KB | Output is correct |
13 | Correct | 36 ms | 47480 KB | Output is correct |
14 | Correct | 36 ms | 47480 KB | Output is correct |
15 | Correct | 35 ms | 47488 KB | Output is correct |
16 | Correct | 35 ms | 47480 KB | Output is correct |
17 | Correct | 35 ms | 47488 KB | Output is correct |
18 | Correct | 37 ms | 47480 KB | Output is correct |
19 | Correct | 35 ms | 47488 KB | Output is correct |
20 | Correct | 36 ms | 47480 KB | Output is correct |
21 | Correct | 35 ms | 47480 KB | Output is correct |
22 | Correct | 35 ms | 47480 KB | Output is correct |
23 | Correct | 37 ms | 47480 KB | Output is correct |
24 | Correct | 36 ms | 47488 KB | Output is correct |
25 | Correct | 36 ms | 47356 KB | Output is correct |
26 | Correct | 36 ms | 47488 KB | Output is correct |
27 | Correct | 37 ms | 47532 KB | Output is correct |
28 | Correct | 36 ms | 47480 KB | Output is correct |
29 | Correct | 36 ms | 47380 KB | Output is correct |
30 | Correct | 36 ms | 47480 KB | Output is correct |
31 | Correct | 35 ms | 47360 KB | Output is correct |
32 | Correct | 38 ms | 47360 KB | Output is correct |
33 | Correct | 35 ms | 47488 KB | Output is correct |
34 | Correct | 35 ms | 47480 KB | Output is correct |
35 | Correct | 36 ms | 47352 KB | Output is correct |
36 | Correct | 35 ms | 47360 KB | Output is correct |
37 | Correct | 35 ms | 47480 KB | Output is correct |
38 | Correct | 35 ms | 47480 KB | Output is correct |
39 | Correct | 35 ms | 47480 KB | Output is correct |
40 | Correct | 36 ms | 47488 KB | Output is correct |
41 | Correct | 35 ms | 47352 KB | Output is correct |
42 | Correct | 37 ms | 47608 KB | Output is correct |
43 | Correct | 35 ms | 47392 KB | Output is correct |
44 | Correct | 32 ms | 47224 KB | Output is correct |
45 | Correct | 33 ms | 47232 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 36 ms | 47488 KB | Output is correct |
2 | Correct | 37 ms | 47480 KB | Output is correct |
3 | Correct | 36 ms | 47360 KB | Output is correct |
4 | Correct | 36 ms | 47396 KB | Output is correct |
5 | Correct | 36 ms | 47480 KB | Output is correct |
6 | Correct | 38 ms | 47480 KB | Output is correct |
7 | Correct | 36 ms | 47488 KB | Output is correct |
8 | Correct | 36 ms | 47488 KB | Output is correct |
9 | Correct | 36 ms | 47480 KB | Output is correct |
10 | Correct | 35 ms | 47488 KB | Output is correct |
11 | Correct | 36 ms | 47488 KB | Output is correct |
12 | Correct | 35 ms | 47488 KB | Output is correct |
13 | Correct | 36 ms | 47480 KB | Output is correct |
14 | Correct | 36 ms | 47480 KB | Output is correct |
15 | Correct | 35 ms | 47488 KB | Output is correct |
16 | Correct | 35 ms | 47480 KB | Output is correct |
17 | Correct | 35 ms | 47488 KB | Output is correct |
18 | Correct | 37 ms | 47480 KB | Output is correct |
19 | Correct | 35 ms | 47488 KB | Output is correct |
20 | Correct | 36 ms | 47480 KB | Output is correct |
21 | Correct | 35 ms | 47480 KB | Output is correct |
22 | Correct | 35 ms | 47480 KB | Output is correct |
23 | Correct | 37 ms | 47480 KB | Output is correct |
24 | Correct | 36 ms | 47488 KB | Output is correct |
25 | Correct | 36 ms | 47356 KB | Output is correct |
26 | Correct | 36 ms | 47488 KB | Output is correct |
27 | Correct | 37 ms | 47532 KB | Output is correct |
28 | Correct | 36 ms | 47480 KB | Output is correct |
29 | Correct | 36 ms | 47380 KB | Output is correct |
30 | Correct | 36 ms | 47480 KB | Output is correct |
31 | Correct | 35 ms | 47360 KB | Output is correct |
32 | Correct | 38 ms | 47360 KB | Output is correct |
33 | Correct | 35 ms | 47488 KB | Output is correct |
34 | Correct | 35 ms | 47480 KB | Output is correct |
35 | Correct | 36 ms | 47352 KB | Output is correct |
36 | Correct | 35 ms | 47360 KB | Output is correct |
37 | Correct | 35 ms | 47480 KB | Output is correct |
38 | Correct | 35 ms | 47480 KB | Output is correct |
39 | Correct | 35 ms | 47480 KB | Output is correct |
40 | Correct | 36 ms | 47488 KB | Output is correct |
41 | Correct | 35 ms | 47352 KB | Output is correct |
42 | Correct | 37 ms | 47608 KB | Output is correct |
43 | Correct | 35 ms | 47392 KB | Output is correct |
44 | Correct | 32 ms | 47224 KB | Output is correct |
45 | Correct | 33 ms | 47232 KB | Output is correct |
46 | Correct | 249 ms | 52600 KB | Output is correct |
47 | Correct | 258 ms | 53876 KB | Output is correct |
48 | Correct | 230 ms | 54000 KB | Output is correct |
49 | Correct | 238 ms | 53876 KB | Output is correct |
50 | Correct | 247 ms | 53872 KB | Output is correct |
51 | Correct | 232 ms | 53876 KB | Output is correct |
52 | Correct | 237 ms | 56312 KB | Output is correct |
53 | Correct | 238 ms | 56472 KB | Output is correct |
54 | Correct | 210 ms | 56440 KB | Output is correct |
55 | Correct | 181 ms | 56440 KB | Output is correct |
56 | Correct | 208 ms | 56312 KB | Output is correct |
57 | Correct | 213 ms | 56440 KB | Output is correct |
58 | Correct | 232 ms | 54136 KB | Output is correct |
59 | Correct | 237 ms | 54264 KB | Output is correct |
60 | Correct | 234 ms | 54136 KB | Output is correct |
61 | Correct | 211 ms | 54232 KB | Output is correct |
62 | Correct | 189 ms | 54184 KB | Output is correct |
63 | Correct | 215 ms | 54308 KB | Output is correct |
64 | Correct | 243 ms | 54136 KB | Output is correct |
65 | Correct | 242 ms | 54136 KB | Output is correct |
66 | Correct | 226 ms | 54116 KB | Output is correct |
67 | Correct | 217 ms | 54220 KB | Output is correct |
68 | Correct | 235 ms | 54264 KB | Output is correct |
69 | Correct | 236 ms | 54136 KB | Output is correct |
70 | Correct | 247 ms | 54072 KB | Output is correct |
71 | Correct | 245 ms | 54008 KB | Output is correct |
72 | Correct | 246 ms | 54008 KB | Output is correct |
73 | Correct | 235 ms | 54008 KB | Output is correct |
74 | Correct | 208 ms | 54008 KB | Output is correct |
75 | Correct | 231 ms | 54012 KB | Output is correct |
76 | Correct | 209 ms | 52664 KB | Output is correct |
77 | Correct | 200 ms | 52128 KB | Output is correct |
78 | Correct | 186 ms | 56312 KB | Output is correct |
79 | Correct | 186 ms | 54264 KB | Output is correct |
80 | Correct | 204 ms | 52600 KB | Output is correct |
81 | Correct | 205 ms | 52216 KB | Output is correct |
82 | Correct | 180 ms | 56440 KB | Output is correct |
83 | Correct | 194 ms | 54264 KB | Output is correct |
84 | Correct | 247 ms | 54104 KB | Output is correct |
85 | Correct | 254 ms | 54132 KB | Output is correct |
86 | Correct | 255 ms | 54132 KB | Output is correct |
87 | Correct | 212 ms | 52976 KB | Output is correct |
88 | Correct | 257 ms | 54132 KB | Output is correct |