# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
260218 | 2020-08-09T19:20:07 Z | patrikpavic2 | Two Dishes (JOI19_dishes) | C++17 | 2970 ms | 173248 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]; if(P[i] <= 0){ del[SS[i] + 1] -= P[i]; pocisti(SS[i] + 1); } for(int j : brisi[i - 1]){ if(del[j] >= 0){ mora[j] = 0; pocisti(j); } } if(P[i] > 0){ del[SS[i] + 1] -= P[i]; pocisti(SS[i] + 1); } for(int j : brisi[i - 1]){ if(del[j] < 0){ 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 | 322 ms | 50400 KB | Output is correct |
2 | Correct | 295 ms | 41832 KB | Output is correct |
3 | Correct | 282 ms | 40036 KB | Output is correct |
4 | Correct | 292 ms | 47448 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 267 ms | 40936 KB | Output is correct |
7 | Correct | 125 ms | 34408 KB | Output is correct |
8 | Correct | 122 ms | 29964 KB | Output is correct |
9 | Correct | 234 ms | 40036 KB | Output is correct |
10 | Correct | 228 ms | 44640 KB | Output is correct |
11 | Correct | 183 ms | 40040 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 14 ms | 23936 KB | Output is correct |
3 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
7 | Correct | 15 ms | 23936 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 15 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 15 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23840 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 |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 14 ms | 23936 KB | Output is correct |
3 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
7 | Correct | 15 ms | 23936 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 15 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 15 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23840 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 | 24064 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24064 KB | Output is correct |
20 | Correct | 18 ms | 24184 KB | Output is correct |
21 | Correct | 18 ms | 24192 KB | Output is correct |
22 | Correct | 18 ms | 24064 KB | Output is correct |
23 | Correct | 18 ms | 24064 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 14 ms | 23936 KB | Output is correct |
3 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
7 | Correct | 15 ms | 23936 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 15 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 15 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23840 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 | 24064 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24064 KB | Output is correct |
20 | Correct | 18 ms | 24184 KB | Output is correct |
21 | Correct | 18 ms | 24192 KB | Output is correct |
22 | Correct | 18 ms | 24064 KB | Output is correct |
23 | Correct | 18 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 39148 KB | Output is correct |
25 | Correct | 303 ms | 47584 KB | Output is correct |
26 | Correct | 235 ms | 39016 KB | Output is correct |
27 | Correct | 308 ms | 53864 KB | Output is correct |
28 | Correct | 288 ms | 40036 KB | Output is correct |
29 | Correct | 205 ms | 40036 KB | Output is correct |
30 | Correct | 453 ms | 42084 KB | Output is correct |
31 | Correct | 136 ms | 37736 KB | Output is correct |
32 | Correct | 116 ms | 29932 KB | Output is correct |
33 | Correct | 336 ms | 40544 KB | Output is correct |
34 | Correct | 394 ms | 44576 KB | Output is correct |
35 | Correct | 371 ms | 42080 KB | Output is correct |
36 | Correct | 367 ms | 42004 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 14 ms | 23936 KB | Output is correct |
3 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
7 | Correct | 15 ms | 23936 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 15 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 15 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23840 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 | 24064 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24064 KB | Output is correct |
20 | Correct | 18 ms | 24184 KB | Output is correct |
21 | Correct | 18 ms | 24192 KB | Output is correct |
22 | Correct | 18 ms | 24064 KB | Output is correct |
23 | Correct | 18 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 39148 KB | Output is correct |
25 | Correct | 303 ms | 47584 KB | Output is correct |
26 | Correct | 235 ms | 39016 KB | Output is correct |
27 | Correct | 308 ms | 53864 KB | Output is correct |
28 | Correct | 288 ms | 40036 KB | Output is correct |
29 | Correct | 205 ms | 40036 KB | Output is correct |
30 | Correct | 453 ms | 42084 KB | Output is correct |
31 | Correct | 136 ms | 37736 KB | Output is correct |
32 | Correct | 116 ms | 29932 KB | Output is correct |
33 | Correct | 336 ms | 40544 KB | Output is correct |
34 | Correct | 394 ms | 44576 KB | Output is correct |
35 | Correct | 371 ms | 42080 KB | Output is correct |
36 | Correct | 367 ms | 42004 KB | Output is correct |
37 | Correct | 269 ms | 39260 KB | Output is correct |
38 | Correct | 346 ms | 53996 KB | Output is correct |
39 | Correct | 346 ms | 53856 KB | Output is correct |
40 | Correct | 264 ms | 44452 KB | Output is correct |
41 | Correct | 15 ms | 23936 KB | Output is correct |
42 | Correct | 518 ms | 42356 KB | Output is correct |
43 | Correct | 373 ms | 40544 KB | Output is correct |
44 | Correct | 419 ms | 44512 KB | Output is correct |
45 | Correct | 414 ms | 42208 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 15 ms | 23936 KB | Output is correct |
2 | Correct | 14 ms | 23936 KB | Output is correct |
3 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
7 | Correct | 15 ms | 23936 KB | Output is correct |
8 | Correct | 15 ms | 23936 KB | Output is correct |
9 | Correct | 15 ms | 23936 KB | Output is correct |
10 | Correct | 15 ms | 23936 KB | Output is correct |
11 | Correct | 15 ms | 23936 KB | Output is correct |
12 | Correct | 15 ms | 23840 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 | 24064 KB | Output is correct |
18 | Correct | 17 ms | 24192 KB | Output is correct |
19 | Correct | 18 ms | 24064 KB | Output is correct |
20 | Correct | 18 ms | 24184 KB | Output is correct |
21 | Correct | 18 ms | 24192 KB | Output is correct |
22 | Correct | 18 ms | 24064 KB | Output is correct |
23 | Correct | 18 ms | 24064 KB | Output is correct |
24 | Correct | 220 ms | 39148 KB | Output is correct |
25 | Correct | 303 ms | 47584 KB | Output is correct |
26 | Correct | 235 ms | 39016 KB | Output is correct |
27 | Correct | 308 ms | 53864 KB | Output is correct |
28 | Correct | 288 ms | 40036 KB | Output is correct |
29 | Correct | 205 ms | 40036 KB | Output is correct |
30 | Correct | 453 ms | 42084 KB | Output is correct |
31 | Correct | 136 ms | 37736 KB | Output is correct |
32 | Correct | 116 ms | 29932 KB | Output is correct |
33 | Correct | 336 ms | 40544 KB | Output is correct |
34 | Correct | 394 ms | 44576 KB | Output is correct |
35 | Correct | 371 ms | 42080 KB | Output is correct |
36 | Correct | 367 ms | 42004 KB | Output is correct |
37 | Correct | 269 ms | 39260 KB | Output is correct |
38 | Correct | 346 ms | 53996 KB | Output is correct |
39 | Correct | 346 ms | 53856 KB | Output is correct |
40 | Correct | 264 ms | 44452 KB | Output is correct |
41 | Correct | 15 ms | 23936 KB | Output is correct |
42 | Correct | 518 ms | 42356 KB | Output is correct |
43 | Correct | 373 ms | 40544 KB | Output is correct |
44 | Correct | 419 ms | 44512 KB | Output is correct |
45 | Correct | 414 ms | 42208 KB | Output is correct |
46 | Correct | 1375 ms | 98504 KB | Output is correct |
47 | Correct | 1752 ms | 172908 KB | Output is correct |
48 | Correct | 1878 ms | 173248 KB | Output is correct |
49 | Correct | 1250 ms | 126400 KB | Output is correct |
50 | Correct | 2970 ms | 115060 KB | Output is correct |
51 | Correct | 2043 ms | 105060 KB | Output is correct |
52 | Correct | 2416 ms | 122548 KB | Output is correct |
53 | Correct | 2483 ms | 114608 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 322 ms | 50400 KB | Output is correct |
2 | Correct | 295 ms | 41832 KB | Output is correct |
3 | Correct | 282 ms | 40036 KB | Output is correct |
4 | Correct | 292 ms | 47448 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 267 ms | 40936 KB | Output is correct |
7 | Correct | 125 ms | 34408 KB | Output is correct |
8 | Correct | 122 ms | 29964 KB | Output is correct |
9 | Correct | 234 ms | 40036 KB | Output is correct |
10 | Correct | 228 ms | 44640 KB | Output is correct |
11 | Correct | 183 ms | 40040 KB | Output is correct |
12 | Correct | 15 ms | 23936 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
18 | Correct | 15 ms | 23936 KB | Output is correct |
19 | Correct | 15 ms | 23936 KB | Output is correct |
20 | Correct | 15 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23936 KB | Output is correct |
23 | Correct | 15 ms | 23840 KB | Output is correct |
24 | Correct | 15 ms | 23936 KB | Output is correct |
25 | Correct | 15 ms | 23936 KB | Output is correct |
26 | Correct | 15 ms | 23936 KB | Output is correct |
27 | Correct | 15 ms | 23936 KB | Output is correct |
28 | Correct | 17 ms | 24064 KB | Output is correct |
29 | Correct | 17 ms | 24192 KB | Output is correct |
30 | Correct | 18 ms | 24064 KB | Output is correct |
31 | Correct | 18 ms | 24184 KB | Output is correct |
32 | Correct | 18 ms | 24192 KB | Output is correct |
33 | Correct | 18 ms | 24064 KB | Output is correct |
34 | Correct | 18 ms | 24064 KB | Output is correct |
35 | Correct | 220 ms | 39148 KB | Output is correct |
36 | Correct | 303 ms | 47584 KB | Output is correct |
37 | Correct | 235 ms | 39016 KB | Output is correct |
38 | Correct | 308 ms | 53864 KB | Output is correct |
39 | Correct | 288 ms | 40036 KB | Output is correct |
40 | Correct | 205 ms | 40036 KB | Output is correct |
41 | Correct | 453 ms | 42084 KB | Output is correct |
42 | Correct | 136 ms | 37736 KB | Output is correct |
43 | Correct | 116 ms | 29932 KB | Output is correct |
44 | Correct | 336 ms | 40544 KB | Output is correct |
45 | Correct | 394 ms | 44576 KB | Output is correct |
46 | Correct | 371 ms | 42080 KB | Output is correct |
47 | Correct | 367 ms | 42004 KB | Output is correct |
48 | Correct | 269 ms | 39260 KB | Output is correct |
49 | Correct | 346 ms | 53996 KB | Output is correct |
50 | Correct | 346 ms | 53856 KB | Output is correct |
51 | Correct | 264 ms | 44452 KB | Output is correct |
52 | Correct | 15 ms | 23936 KB | Output is correct |
53 | Correct | 518 ms | 42356 KB | Output is correct |
54 | Correct | 373 ms | 40544 KB | Output is correct |
55 | Correct | 419 ms | 44512 KB | Output is correct |
56 | Correct | 414 ms | 42208 KB | Output is correct |
57 | Correct | 326 ms | 48736 KB | Output is correct |
58 | Correct | 288 ms | 44900 KB | Output is correct |
59 | Incorrect | 268 ms | 44768 KB | Output isn't correct |
60 | Halted | 0 ms | 0 KB | - |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 322 ms | 50400 KB | Output is correct |
2 | Correct | 295 ms | 41832 KB | Output is correct |
3 | Correct | 282 ms | 40036 KB | Output is correct |
4 | Correct | 292 ms | 47448 KB | Output is correct |
5 | Correct | 15 ms | 23936 KB | Output is correct |
6 | Correct | 267 ms | 40936 KB | Output is correct |
7 | Correct | 125 ms | 34408 KB | Output is correct |
8 | Correct | 122 ms | 29964 KB | Output is correct |
9 | Correct | 234 ms | 40036 KB | Output is correct |
10 | Correct | 228 ms | 44640 KB | Output is correct |
11 | Correct | 183 ms | 40040 KB | Output is correct |
12 | Correct | 15 ms | 23936 KB | Output is correct |
13 | Correct | 14 ms | 23936 KB | Output is correct |
14 | Correct | 16 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 | 15 ms | 23936 KB | Output is correct |
18 | Correct | 15 ms | 23936 KB | Output is correct |
19 | Correct | 15 ms | 23936 KB | Output is correct |
20 | Correct | 15 ms | 23936 KB | Output is correct |
21 | Correct | 15 ms | 23936 KB | Output is correct |
22 | Correct | 15 ms | 23936 KB | Output is correct |
23 | Correct | 15 ms | 23840 KB | Output is correct |
24 | Correct | 15 ms | 23936 KB | Output is correct |
25 | Correct | 15 ms | 23936 KB | Output is correct |
26 | Correct | 15 ms | 23936 KB | Output is correct |
27 | Correct | 15 ms | 23936 KB | Output is correct |
28 | Correct | 17 ms | 24064 KB | Output is correct |
29 | Correct | 17 ms | 24192 KB | Output is correct |
30 | Correct | 18 ms | 24064 KB | Output is correct |
31 | Correct | 18 ms | 24184 KB | Output is correct |
32 | Correct | 18 ms | 24192 KB | Output is correct |
33 | Correct | 18 ms | 24064 KB | Output is correct |
34 | Correct | 18 ms | 24064 KB | Output is correct |
35 | Correct | 220 ms | 39148 KB | Output is correct |
36 | Correct | 303 ms | 47584 KB | Output is correct |
37 | Correct | 235 ms | 39016 KB | Output is correct |
38 | Correct | 308 ms | 53864 KB | Output is correct |
39 | Correct | 288 ms | 40036 KB | Output is correct |
40 | Correct | 205 ms | 40036 KB | Output is correct |
41 | Correct | 453 ms | 42084 KB | Output is correct |
42 | Correct | 136 ms | 37736 KB | Output is correct |
43 | Correct | 116 ms | 29932 KB | Output is correct |
44 | Correct | 336 ms | 40544 KB | Output is correct |
45 | Correct | 394 ms | 44576 KB | Output is correct |
46 | Correct | 371 ms | 42080 KB | Output is correct |
47 | Correct | 367 ms | 42004 KB | Output is correct |
48 | Correct | 269 ms | 39260 KB | Output is correct |
49 | Correct | 346 ms | 53996 KB | Output is correct |
50 | Correct | 346 ms | 53856 KB | Output is correct |
51 | Correct | 264 ms | 44452 KB | Output is correct |
52 | Correct | 15 ms | 23936 KB | Output is correct |
53 | Correct | 518 ms | 42356 KB | Output is correct |
54 | Correct | 373 ms | 40544 KB | Output is correct |
55 | Correct | 419 ms | 44512 KB | Output is correct |
56 | Correct | 414 ms | 42208 KB | Output is correct |
57 | Correct | 1375 ms | 98504 KB | Output is correct |
58 | Correct | 1752 ms | 172908 KB | Output is correct |
59 | Correct | 1878 ms | 173248 KB | Output is correct |
60 | Correct | 1250 ms | 126400 KB | Output is correct |
61 | Correct | 2970 ms | 115060 KB | Output is correct |
62 | Correct | 2043 ms | 105060 KB | Output is correct |
63 | Correct | 2416 ms | 122548 KB | Output is correct |
64 | Correct | 2483 ms | 114608 KB | Output is correct |
65 | Correct | 326 ms | 48736 KB | Output is correct |
66 | Correct | 288 ms | 44900 KB | Output is correct |
67 | Incorrect | 268 ms | 44768 KB | Output isn't correct |
68 | Halted | 0 ms | 0 KB | - |