# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259189 | 2020-08-07T10:50:51 Z | patrikpavic2 | Two Dishes (JOI19_dishes) | C++17 | 2824 ms | 172944 KB |
#include <cstdio> #include <cstring> #include <vector> #include <set> #include <algorithm> #define PB push_back using namespace std; typedef long long ll; const int N = 1e6 + 500; const ll INF = 1e18; ll del[N], mora[N], S[N], T[N]; int n, m; int Q[N], P[N], A[N], B[N]; int SS[N], TT[N]; vector < ll > v, v2; vector < int > brisi[N]; set < int > raz; void pocisti(int sad){ if(del[sad] > mora[sad]){ raz.insert(sad); return; } if(del[sad] == mora[sad] && raz.count(sad)) raz.erase(sad); if(del[sad] >= mora[sad]) return; ll trb = mora[sad] - del[sad]; del[sad] = mora[sad]; sad++; while(sad <= m && trb > 0){ if(del[sad] - mora[sad] > trb){ del[sad] -= trb; break; } trb -= (del[sad] - mora[sad]); del[sad] = mora[sad]; raz.erase(sad); if(raz.lower_bound(sad) == raz.end()) break; sad = *(raz.upper_bound(sad)); } } int main(){ scanf("%d%d", &n, &m); for(int i = 1;i <= n;i++) scanf("%d%lld%d", A + i, S + i, P + i); for(int i = 1;i <= m;i++) scanf("%d%lld%d", B + i, T + i, Q + i); ll cur = 0; v.PB(cur); for(int i = 1;i <= m;i++) cur += B[i], v.PB(cur); cur = 0; v2.PB(cur); for(int i = 1;i <= n;i++){ cur += A[i]; v2.PB(cur); if(S[i] < cur) P[i] = 0, S[i] = cur; SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1; } cur = 0; for(int i = 1;i <= m;i++){ cur += B[i]; if(T[i] < cur) Q[i] = 0, T[i] = cur; TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1; } for(int i = m;i >= 1;i--){ del[i] = Q[i], mora[i] = Q[i]; if(TT[i]){ brisi[TT[i]].PB(i); } else{ mora[i] = 0; pocisti(i); } } for(int i = 1;i <= n;i++){ del[0] += P[i]; del[SS[i] + 1] -= P[i]; pocisti(SS[i] + 1); if(i == n) break; for(int j : brisi[i]){ mora[j] = 0; pocisti(j); } } ll ans = 0; for(int i = 0;i <= m;i++) ans += del[i]; printf("%lld\n", ans); }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 310 ms | 52520 KB | Output is correct |
2 | Correct | 267 ms | 44284 KB | Output is correct |
3 | Correct | 234 ms | 41448 KB | Output is correct |
4 | Correct | 285 ms | 48864 KB | Output is correct |
5 | Correct | 14 ms | 23936 KB | Output is correct |
6 | Correct | 264 ms | 42340 KB | Output is correct |
7 | Correct | 117 ms | 35944 KB | Output is correct |
8 | Correct | 124 ms | 31340 KB | Output is correct |
9 | Correct | 235 ms | 41448 KB | Output is correct |
10 | Correct | 226 ms | 45904 KB | Output is correct |
11 | Correct | 174 ms | 41448 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 15 ms | 23936 KB | Output is correct |
3 | Correct | 15 ms | 23936 KB | Output is correct |
4 | Correct | 15 ms | 23936 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 17 ms | 23936 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 17 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 17 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 17 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 17 ms | 23936 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 15 ms | 23936 KB | Output is correct |
3 | Correct | 15 ms | 23936 KB | Output is correct |
4 | Correct | 15 ms | 23936 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 17 ms | 23936 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 17 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 17 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 17 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 17 ms | 23936 KB | Output is correct |
17 | Correct | 19 ms | 24192 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24192 KB | Output is correct |
20 | Correct | 17 ms | 24192 KB | Output is correct |
21 | Correct | 17 ms | 24192 KB | Output is correct |
22 | Correct | 17 ms | 24064 KB | Output is correct |
23 | Correct | 17 ms | 24064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 15 ms | 23936 KB | Output is correct |
3 | Correct | 15 ms | 23936 KB | Output is correct |
4 | Correct | 15 ms | 23936 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 17 ms | 23936 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 17 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 17 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 17 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 17 ms | 23936 KB | Output is correct |
17 | Correct | 19 ms | 24192 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24192 KB | Output is correct |
20 | Correct | 17 ms | 24192 KB | Output is correct |
21 | Correct | 17 ms | 24192 KB | Output is correct |
22 | Correct | 17 ms | 24064 KB | Output is correct |
23 | Correct | 17 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 42940 KB | Output is correct |
25 | Correct | 279 ms | 48980 KB | Output is correct |
26 | Correct | 231 ms | 40472 KB | Output is correct |
27 | Correct | 288 ms | 55264 KB | Output is correct |
28 | Correct | 288 ms | 41544 KB | Output is correct |
29 | Correct | 198 ms | 41444 KB | Output is correct |
30 | Correct | 431 ms | 43572 KB | Output is correct |
31 | Correct | 133 ms | 39400 KB | Output is correct |
32 | Correct | 112 ms | 31596 KB | Output is correct |
33 | Correct | 327 ms | 41956 KB | Output is correct |
34 | Correct | 378 ms | 45944 KB | Output is correct |
35 | Correct | 353 ms | 43744 KB | Output is correct |
36 | Correct | 347 ms | 43744 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 15 ms | 23936 KB | Output is correct |
3 | Correct | 15 ms | 23936 KB | Output is correct |
4 | Correct | 15 ms | 23936 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 17 ms | 23936 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 17 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 17 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 17 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 17 ms | 23936 KB | Output is correct |
17 | Correct | 19 ms | 24192 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24192 KB | Output is correct |
20 | Correct | 17 ms | 24192 KB | Output is correct |
21 | Correct | 17 ms | 24192 KB | Output is correct |
22 | Correct | 17 ms | 24064 KB | Output is correct |
23 | Correct | 17 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 42940 KB | Output is correct |
25 | Correct | 279 ms | 48980 KB | Output is correct |
26 | Correct | 231 ms | 40472 KB | Output is correct |
27 | Correct | 288 ms | 55264 KB | Output is correct |
28 | Correct | 288 ms | 41544 KB | Output is correct |
29 | Correct | 198 ms | 41444 KB | Output is correct |
30 | Correct | 431 ms | 43572 KB | Output is correct |
31 | Correct | 133 ms | 39400 KB | Output is correct |
32 | Correct | 112 ms | 31596 KB | Output is correct |
33 | Correct | 327 ms | 41956 KB | Output is correct |
34 | Correct | 378 ms | 45944 KB | Output is correct |
35 | Correct | 353 ms | 43744 KB | Output is correct |
36 | Correct | 347 ms | 43744 KB | Output is correct |
37 | Correct | 275 ms | 40572 KB | Output is correct |
38 | Correct | 329 ms | 55264 KB | Output is correct |
39 | Correct | 349 ms | 55488 KB | Output is correct |
40 | Correct | 257 ms | 46052 KB | Output is correct |
41 | Correct | 15 ms | 23936 KB | Output is correct |
42 | Correct | 488 ms | 43864 KB | Output is correct |
43 | Correct | 373 ms | 42080 KB | Output is correct |
44 | Correct | 425 ms | 45920 KB | Output is correct |
45 | Correct | 397 ms | 44000 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 15 ms | 23936 KB | Output is correct |
3 | Correct | 15 ms | 23936 KB | Output is correct |
4 | Correct | 15 ms | 23936 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 17 ms | 23936 KB | Output is correct |
7 | Correct | 17 ms | 23808 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 17 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 17 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23808 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 17 ms | 23936 KB | Output is correct |
15 | Correct | 17 ms | 23936 KB | Output is correct |
16 | Correct | 17 ms | 23936 KB | Output is correct |
17 | Correct | 19 ms | 24192 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24192 KB | Output is correct |
20 | Correct | 17 ms | 24192 KB | Output is correct |
21 | Correct | 17 ms | 24192 KB | Output is correct |
22 | Correct | 17 ms | 24064 KB | Output is correct |
23 | Correct | 17 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 42940 KB | Output is correct |
25 | Correct | 279 ms | 48980 KB | Output is correct |
26 | Correct | 231 ms | 40472 KB | Output is correct |
27 | Correct | 288 ms | 55264 KB | Output is correct |
28 | Correct | 288 ms | 41544 KB | Output is correct |
29 | Correct | 198 ms | 41444 KB | Output is correct |
30 | Correct | 431 ms | 43572 KB | Output is correct |
31 | Correct | 133 ms | 39400 KB | Output is correct |
32 | Correct | 112 ms | 31596 KB | Output is correct |
33 | Correct | 327 ms | 41956 KB | Output is correct |
34 | Correct | 378 ms | 45944 KB | Output is correct |
35 | Correct | 353 ms | 43744 KB | Output is correct |
36 | Correct | 347 ms | 43744 KB | Output is correct |
37 | Correct | 275 ms | 40572 KB | Output is correct |
38 | Correct | 329 ms | 55264 KB | Output is correct |
39 | Correct | 349 ms | 55488 KB | Output is correct |
40 | Correct | 257 ms | 46052 KB | Output is correct |
41 | Correct | 15 ms | 23936 KB | Output is correct |
42 | Correct | 488 ms | 43864 KB | Output is correct |
43 | Correct | 373 ms | 42080 KB | Output is correct |
44 | Correct | 425 ms | 45920 KB | Output is correct |
45 | Correct | 397 ms | 44000 KB | Output is correct |
46 | Correct | 1295 ms | 98532 KB | Output is correct |
47 | Correct | 1653 ms | 172944 KB | Output is correct |
48 | Correct | 1762 ms | 172736 KB | Output is correct |
49 | Correct | 1221 ms | 125868 KB | Output is correct |
50 | Correct | 2824 ms | 114736 KB | Output is correct |
51 | Correct | 1978 ms | 104808 KB | Output is correct |
52 | Correct | 2391 ms | 122148 KB | Output is correct |
53 | Correct | 2386 ms | 114244 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 310 ms | 52520 KB | Output is correct |
2 | Correct | 267 ms | 44284 KB | Output is correct |
3 | Correct | 234 ms | 41448 KB | Output is correct |
4 | Correct | 285 ms | 48864 KB | Output is correct |
5 | Correct | 14 ms | 23936 KB | Output is correct |
6 | Correct | 264 ms | 42340 KB | Output is correct |
7 | Correct | 117 ms | 35944 KB | Output is correct |
8 | Correct | 124 ms | 31340 KB | Output is correct |
9 | Correct | 235 ms | 41448 KB | Output is correct |
10 | Correct | 226 ms | 45904 KB | Output is correct |
11 | Correct | 174 ms | 41448 KB | Output is correct |
12 | Correct | 15 ms | 23936 KB | Output is correct |
13 | Correct | 15 ms | 23936 KB | Output is correct |
14 | Correct | 15 ms | 23936 KB | Output is correct |
15 | Correct | 15 ms | 23936 KB | Output is correct |
16 | Correct | 15 ms | 23936 KB | Output is correct |
17 | Correct | 17 ms | 23936 KB | Output is correct |
18 | Correct | 17 ms | 23808 KB | Output is correct |
19 | Correct | 15 ms | 23936 KB | Output is correct |
20 | Correct | 17 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 17 ms | 23936 KB | Output is correct |
23 | Correct | 15 ms | 23808 KB | Output is correct |
24 | Correct | 14 ms | 23936 KB | Output is correct |
25 | Correct | 17 ms | 23936 KB | Output is correct |
26 | Correct | 17 ms | 23936 KB | Output is correct |
27 | Correct | 17 ms | 23936 KB | Output is correct |
28 | Correct | 19 ms | 24192 KB | Output is correct |
29 | Correct | 17 ms | 24192 KB | Output is correct |
30 | Correct | 18 ms | 24192 KB | Output is correct |
31 | Correct | 17 ms | 24192 KB | Output is correct |
32 | Correct | 17 ms | 24192 KB | Output is correct |
33 | Correct | 17 ms | 24064 KB | Output is correct |
34 | Correct | 17 ms | 24064 KB | Output is correct |
35 | Correct | 220 ms | 42940 KB | Output is correct |
36 | Correct | 279 ms | 48980 KB | Output is correct |
37 | Correct | 231 ms | 40472 KB | Output is correct |
38 | Correct | 288 ms | 55264 KB | Output is correct |
39 | Correct | 288 ms | 41544 KB | Output is correct |
40 | Correct | 198 ms | 41444 KB | Output is correct |
41 | Correct | 431 ms | 43572 KB | Output is correct |
42 | Correct | 133 ms | 39400 KB | Output is correct |
43 | Correct | 112 ms | 31596 KB | Output is correct |
44 | Correct | 327 ms | 41956 KB | Output is correct |
45 | Correct | 378 ms | 45944 KB | Output is correct |
46 | Correct | 353 ms | 43744 KB | Output is correct |
47 | Correct | 347 ms | 43744 KB | Output is correct |
48 | Correct | 275 ms | 40572 KB | Output is correct |
49 | Correct | 329 ms | 55264 KB | Output is correct |
50 | Correct | 349 ms | 55488 KB | Output is correct |
51 | Correct | 257 ms | 46052 KB | Output is correct |
52 | Correct | 15 ms | 23936 KB | Output is correct |
53 | Correct | 488 ms | 43864 KB | Output is correct |
54 | Correct | 373 ms | 42080 KB | Output is correct |
55 | Correct | 425 ms | 45920 KB | Output is correct |
56 | Correct | 397 ms | 44000 KB | Output is correct |
57 | Correct | 317 ms | 48820 KB | Output is correct |
58 | Correct | 307 ms | 45284 KB | Output is correct |
59 | Incorrect | 262 ms | 45280 KB | Output isn't correct |
60 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 310 ms | 52520 KB | Output is correct |
2 | Correct | 267 ms | 44284 KB | Output is correct |
3 | Correct | 234 ms | 41448 KB | Output is correct |
4 | Correct | 285 ms | 48864 KB | Output is correct |
5 | Correct | 14 ms | 23936 KB | Output is correct |
6 | Correct | 264 ms | 42340 KB | Output is correct |
7 | Correct | 117 ms | 35944 KB | Output is correct |
8 | Correct | 124 ms | 31340 KB | Output is correct |
9 | Correct | 235 ms | 41448 KB | Output is correct |
10 | Correct | 226 ms | 45904 KB | Output is correct |
11 | Correct | 174 ms | 41448 KB | Output is correct |
12 | Correct | 15 ms | 23936 KB | Output is correct |
13 | Correct | 15 ms | 23936 KB | Output is correct |
14 | Correct | 15 ms | 23936 KB | Output is correct |
15 | Correct | 15 ms | 23936 KB | Output is correct |
16 | Correct | 15 ms | 23936 KB | Output is correct |
17 | Correct | 17 ms | 23936 KB | Output is correct |
18 | Correct | 17 ms | 23808 KB | Output is correct |
19 | Correct | 15 ms | 23936 KB | Output is correct |
20 | Correct | 17 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 17 ms | 23936 KB | Output is correct |
23 | Correct | 15 ms | 23808 KB | Output is correct |
24 | Correct | 14 ms | 23936 KB | Output is correct |
25 | Correct | 17 ms | 23936 KB | Output is correct |
26 | Correct | 17 ms | 23936 KB | Output is correct |
27 | Correct | 17 ms | 23936 KB | Output is correct |
28 | Correct | 19 ms | 24192 KB | Output is correct |
29 | Correct | 17 ms | 24192 KB | Output is correct |
30 | Correct | 18 ms | 24192 KB | Output is correct |
31 | Correct | 17 ms | 24192 KB | Output is correct |
32 | Correct | 17 ms | 24192 KB | Output is correct |
33 | Correct | 17 ms | 24064 KB | Output is correct |
34 | Correct | 17 ms | 24064 KB | Output is correct |
35 | Correct | 220 ms | 42940 KB | Output is correct |
36 | Correct | 279 ms | 48980 KB | Output is correct |
37 | Correct | 231 ms | 40472 KB | Output is correct |
38 | Correct | 288 ms | 55264 KB | Output is correct |
39 | Correct | 288 ms | 41544 KB | Output is correct |
40 | Correct | 198 ms | 41444 KB | Output is correct |
41 | Correct | 431 ms | 43572 KB | Output is correct |
42 | Correct | 133 ms | 39400 KB | Output is correct |
43 | Correct | 112 ms | 31596 KB | Output is correct |
44 | Correct | 327 ms | 41956 KB | Output is correct |
45 | Correct | 378 ms | 45944 KB | Output is correct |
46 | Correct | 353 ms | 43744 KB | Output is correct |
47 | Correct | 347 ms | 43744 KB | Output is correct |
48 | Correct | 275 ms | 40572 KB | Output is correct |
49 | Correct | 329 ms | 55264 KB | Output is correct |
50 | Correct | 349 ms | 55488 KB | Output is correct |
51 | Correct | 257 ms | 46052 KB | Output is correct |
52 | Correct | 15 ms | 23936 KB | Output is correct |
53 | Correct | 488 ms | 43864 KB | Output is correct |
54 | Correct | 373 ms | 42080 KB | Output is correct |
55 | Correct | 425 ms | 45920 KB | Output is correct |
56 | Correct | 397 ms | 44000 KB | Output is correct |
57 | Correct | 1295 ms | 98532 KB | Output is correct |
58 | Correct | 1653 ms | 172944 KB | Output is correct |
59 | Correct | 1762 ms | 172736 KB | Output is correct |
60 | Correct | 1221 ms | 125868 KB | Output is correct |
61 | Correct | 2824 ms | 114736 KB | Output is correct |
62 | Correct | 1978 ms | 104808 KB | Output is correct |
63 | Correct | 2391 ms | 122148 KB | Output is correct |
64 | Correct | 2386 ms | 114244 KB | Output is correct |
65 | Correct | 317 ms | 48820 KB | Output is correct |
66 | Correct | 307 ms | 45284 KB | Output is correct |
67 | Incorrect | 262 ms | 45280 KB | Output isn't correct |
68 | Halted | 0 ms | 0 KB | - |