Submission #572178

# Submission time Handle Problem Language Result Execution time Memory
572178 2022-06-03T22:43:49 Z sidon Two Dishes (JOI19_dishes) C++17
100 / 100
2988 ms 371092 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main() {
	ios::sync_with_stdio(0), cin.tie(0);

	int N, M; cin >> N >> M;

	int A[N], S[N], P[N];
	int B[M], T[M], Q[M];

	for(int i = 0; i < N; ++i) {
		cin >> A[i] >> S[i] >> P[i];
		if(i) A[i] += A[i-1];
	}

	for(int i = 0; i < M; ++i) {
		cin >> B[i] >> T[i] >> Q[i];
		if(i) B[i] += B[i-1];
	}

	map<int, int> g[N+1] {{{0, 0}}};
	int ans {};

	for(int i = 0; i < N; ++i) if(S[i] >= A[i]) {
		S[i] = upper_bound(B, B + M, S[i] - A[i]) - B;
		g[i+1][S[i]] += P[i];
	}
	for(int i = 0; i < M; ++i) if(T[i] >= B[i]) {
		T[i] = upper_bound(A, A + N, T[i] - B[i]) - A;
		if(T[i] < N) g[T[i]+1][i] -= Q[i];
		ans += Q[i];
	}

	map<int, int> s;

	for(int i = 1; i <= N; ++i) {
		g[i][M] += 0;

		int cur {};

		for(auto [r, val] : g[i]) {
			cur += val;
			s[r+1] -= val;
		}
		s[0] += cur;

		for(auto [r, val] : g[i]) {
			auto f = s.upper_bound(r);
			while(f != s.end() && f->first <= M && f->second <= 0) {
				auto nx = next(f) == end(s) ? M + 1 : next(f)->first;
				s[nx] += f->second;
				f = s.erase(f);
			}
		}
	}

	for(int i = 0; i <= M; ++i) ans += s[i];
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 268 ms 60332 KB Output is correct
2 Correct 271 ms 58708 KB Output is correct
3 Correct 215 ms 45052 KB Output is correct
4 Correct 248 ms 52264 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 252 ms 55044 KB Output is correct
7 Correct 110 ms 17912 KB Output is correct
8 Correct 94 ms 27384 KB Output is correct
9 Correct 228 ms 44904 KB Output is correct
10 Correct 225 ms 57168 KB Output is correct
11 Correct 175 ms 44572 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 3 ms 968 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 3 ms 964 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 3 ms 968 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 3 ms 964 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
24 Correct 231 ms 67136 KB Output is correct
25 Correct 399 ms 67144 KB Output is correct
26 Correct 228 ms 67272 KB Output is correct
27 Correct 241 ms 67268 KB Output is correct
28 Correct 245 ms 57672 KB Output is correct
29 Correct 203 ms 51588 KB Output is correct
30 Correct 457 ms 78864 KB Output is correct
31 Correct 139 ms 28916 KB Output is correct
32 Correct 95 ms 38392 KB Output is correct
33 Correct 316 ms 66068 KB Output is correct
34 Correct 394 ms 73420 KB Output is correct
35 Correct 428 ms 72952 KB Output is correct
36 Correct 413 ms 72012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 3 ms 968 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 3 ms 964 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
24 Correct 231 ms 67136 KB Output is correct
25 Correct 399 ms 67144 KB Output is correct
26 Correct 228 ms 67272 KB Output is correct
27 Correct 241 ms 67268 KB Output is correct
28 Correct 245 ms 57672 KB Output is correct
29 Correct 203 ms 51588 KB Output is correct
30 Correct 457 ms 78864 KB Output is correct
31 Correct 139 ms 28916 KB Output is correct
32 Correct 95 ms 38392 KB Output is correct
33 Correct 316 ms 66068 KB Output is correct
34 Correct 394 ms 73420 KB Output is correct
35 Correct 428 ms 72952 KB Output is correct
36 Correct 413 ms 72012 KB Output is correct
37 Correct 256 ms 67020 KB Output is correct
38 Correct 263 ms 61884 KB Output is correct
39 Correct 301 ms 63572 KB Output is correct
40 Correct 230 ms 65744 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 501 ms 78576 KB Output is correct
43 Correct 328 ms 60596 KB Output is correct
44 Correct 440 ms 72660 KB Output is correct
45 Correct 455 ms 75688 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 0 ms 320 KB Output is correct
9 Correct 0 ms 324 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 324 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 0 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 1 ms 212 KB Output is correct
16 Correct 0 ms 316 KB Output is correct
17 Correct 3 ms 968 KB Output is correct
18 Correct 3 ms 884 KB Output is correct
19 Correct 4 ms 980 KB Output is correct
20 Correct 3 ms 852 KB Output is correct
21 Correct 3 ms 980 KB Output is correct
22 Correct 3 ms 964 KB Output is correct
23 Correct 3 ms 980 KB Output is correct
24 Correct 231 ms 67136 KB Output is correct
25 Correct 399 ms 67144 KB Output is correct
26 Correct 228 ms 67272 KB Output is correct
27 Correct 241 ms 67268 KB Output is correct
28 Correct 245 ms 57672 KB Output is correct
29 Correct 203 ms 51588 KB Output is correct
30 Correct 457 ms 78864 KB Output is correct
31 Correct 139 ms 28916 KB Output is correct
32 Correct 95 ms 38392 KB Output is correct
33 Correct 316 ms 66068 KB Output is correct
34 Correct 394 ms 73420 KB Output is correct
35 Correct 428 ms 72952 KB Output is correct
36 Correct 413 ms 72012 KB Output is correct
37 Correct 256 ms 67020 KB Output is correct
38 Correct 263 ms 61884 KB Output is correct
39 Correct 301 ms 63572 KB Output is correct
40 Correct 230 ms 65744 KB Output is correct
41 Correct 0 ms 212 KB Output is correct
42 Correct 501 ms 78576 KB Output is correct
43 Correct 328 ms 60596 KB Output is correct
44 Correct 440 ms 72660 KB Output is correct
45 Correct 455 ms 75688 KB Output is correct
46 Correct 1232 ms 284180 KB Output is correct
47 Correct 1324 ms 285064 KB Output is correct
48 Correct 1462 ms 284324 KB Output is correct
49 Correct 1177 ms 284484 KB Output is correct
50 Correct 2919 ms 345460 KB Output is correct
51 Correct 1840 ms 271964 KB Output is correct
52 Correct 2423 ms 298480 KB Output is correct
53 Correct 2653 ms 338812 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 60332 KB Output is correct
2 Correct 271 ms 58708 KB Output is correct
3 Correct 215 ms 45052 KB Output is correct
4 Correct 248 ms 52264 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 252 ms 55044 KB Output is correct
7 Correct 110 ms 17912 KB Output is correct
8 Correct 94 ms 27384 KB Output is correct
9 Correct 228 ms 44904 KB Output is correct
10 Correct 225 ms 57168 KB Output is correct
11 Correct 175 ms 44572 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 316 KB Output is correct
28 Correct 3 ms 968 KB Output is correct
29 Correct 3 ms 884 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 3 ms 980 KB Output is correct
33 Correct 3 ms 964 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 231 ms 67136 KB Output is correct
36 Correct 399 ms 67144 KB Output is correct
37 Correct 228 ms 67272 KB Output is correct
38 Correct 241 ms 67268 KB Output is correct
39 Correct 245 ms 57672 KB Output is correct
40 Correct 203 ms 51588 KB Output is correct
41 Correct 457 ms 78864 KB Output is correct
42 Correct 139 ms 28916 KB Output is correct
43 Correct 95 ms 38392 KB Output is correct
44 Correct 316 ms 66068 KB Output is correct
45 Correct 394 ms 73420 KB Output is correct
46 Correct 428 ms 72952 KB Output is correct
47 Correct 413 ms 72012 KB Output is correct
48 Correct 256 ms 67020 KB Output is correct
49 Correct 263 ms 61884 KB Output is correct
50 Correct 301 ms 63572 KB Output is correct
51 Correct 230 ms 65744 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 501 ms 78576 KB Output is correct
54 Correct 328 ms 60596 KB Output is correct
55 Correct 440 ms 72660 KB Output is correct
56 Correct 455 ms 75688 KB Output is correct
57 Correct 337 ms 58440 KB Output is correct
58 Correct 253 ms 58244 KB Output is correct
59 Correct 236 ms 58420 KB Output is correct
60 Correct 349 ms 58228 KB Output is correct
61 Correct 392 ms 70832 KB Output is correct
62 Correct 0 ms 212 KB Output is correct
63 Correct 497 ms 69896 KB Output is correct
64 Correct 335 ms 57260 KB Output is correct
65 Correct 418 ms 63560 KB Output is correct
66 Correct 456 ms 75284 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 268 ms 60332 KB Output is correct
2 Correct 271 ms 58708 KB Output is correct
3 Correct 215 ms 45052 KB Output is correct
4 Correct 248 ms 52264 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 252 ms 55044 KB Output is correct
7 Correct 110 ms 17912 KB Output is correct
8 Correct 94 ms 27384 KB Output is correct
9 Correct 228 ms 44904 KB Output is correct
10 Correct 225 ms 57168 KB Output is correct
11 Correct 175 ms 44572 KB Output is correct
12 Correct 0 ms 212 KB Output is correct
13 Correct 1 ms 212 KB Output is correct
14 Correct 1 ms 212 KB Output is correct
15 Correct 0 ms 212 KB Output is correct
16 Correct 1 ms 212 KB Output is correct
17 Correct 0 ms 212 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 0 ms 320 KB Output is correct
20 Correct 0 ms 324 KB Output is correct
21 Correct 1 ms 316 KB Output is correct
22 Correct 1 ms 324 KB Output is correct
23 Correct 0 ms 212 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 1 ms 212 KB Output is correct
26 Correct 1 ms 212 KB Output is correct
27 Correct 0 ms 316 KB Output is correct
28 Correct 3 ms 968 KB Output is correct
29 Correct 3 ms 884 KB Output is correct
30 Correct 4 ms 980 KB Output is correct
31 Correct 3 ms 852 KB Output is correct
32 Correct 3 ms 980 KB Output is correct
33 Correct 3 ms 964 KB Output is correct
34 Correct 3 ms 980 KB Output is correct
35 Correct 231 ms 67136 KB Output is correct
36 Correct 399 ms 67144 KB Output is correct
37 Correct 228 ms 67272 KB Output is correct
38 Correct 241 ms 67268 KB Output is correct
39 Correct 245 ms 57672 KB Output is correct
40 Correct 203 ms 51588 KB Output is correct
41 Correct 457 ms 78864 KB Output is correct
42 Correct 139 ms 28916 KB Output is correct
43 Correct 95 ms 38392 KB Output is correct
44 Correct 316 ms 66068 KB Output is correct
45 Correct 394 ms 73420 KB Output is correct
46 Correct 428 ms 72952 KB Output is correct
47 Correct 413 ms 72012 KB Output is correct
48 Correct 256 ms 67020 KB Output is correct
49 Correct 263 ms 61884 KB Output is correct
50 Correct 301 ms 63572 KB Output is correct
51 Correct 230 ms 65744 KB Output is correct
52 Correct 0 ms 212 KB Output is correct
53 Correct 501 ms 78576 KB Output is correct
54 Correct 328 ms 60596 KB Output is correct
55 Correct 440 ms 72660 KB Output is correct
56 Correct 455 ms 75688 KB Output is correct
57 Correct 1232 ms 284180 KB Output is correct
58 Correct 1324 ms 285064 KB Output is correct
59 Correct 1462 ms 284324 KB Output is correct
60 Correct 1177 ms 284484 KB Output is correct
61 Correct 2919 ms 345460 KB Output is correct
62 Correct 1840 ms 271964 KB Output is correct
63 Correct 2423 ms 298480 KB Output is correct
64 Correct 2653 ms 338812 KB Output is correct
65 Correct 337 ms 58440 KB Output is correct
66 Correct 253 ms 58244 KB Output is correct
67 Correct 236 ms 58420 KB Output is correct
68 Correct 349 ms 58228 KB Output is correct
69 Correct 392 ms 70832 KB Output is correct
70 Correct 0 ms 212 KB Output is correct
71 Correct 497 ms 69896 KB Output is correct
72 Correct 335 ms 57260 KB Output is correct
73 Correct 418 ms 63560 KB Output is correct
74 Correct 456 ms 75284 KB Output is correct
75 Correct 2138 ms 314040 KB Output is correct
76 Correct 1287 ms 313756 KB Output is correct
77 Correct 1237 ms 306864 KB Output is correct
78 Correct 2024 ms 306528 KB Output is correct
79 Correct 2988 ms 371092 KB Output is correct
80 Correct 1896 ms 299416 KB Output is correct
81 Correct 2272 ms 319612 KB Output is correct
82 Correct 2829 ms 352744 KB Output is correct
83 Correct 2782 ms 345184 KB Output is correct