답안 #426457

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
426457 2021-06-14T04:14:42 Z Kevin_Zhang_TW Two Dishes (JOI19_dishes) C++17
100 / 100
3058 ms 242556 KB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb emplace_back
#define AI(i) begin(i), end(i)
template<class T> bool chmin(T &a, T b) { return b < a && (a = b, true); }
template<class T> bool chmax(T &a, T b) { return a < b && (a = b, true); }
#ifdef KEV
#define DE(args...) kout("[ " + string(#args) + " ] = ", args)
void kout() { cerr << endl; }
template<class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ', kout(b...); }
template<class T> void debug(T l, T r) { while (l != r) cerr << *l << " \n"[next(l)==r], ++l; }
#else
#define DE(...) 0
#define debug(...) 0
#endif

const int MAX_N = 1000010, MAX_M = 2005;
const ll inf = 1e16;

int n, m;

ll a[MAX_N], s[MAX_N], p[MAX_N], c[MAX_N];
ll b[MAX_N], t[MAX_N], q[MAX_N], d[MAX_N];

//ll dp[MAX_M][MAX_M];

int32_t main() {
	ios_base::sync_with_stdio(0), cin.tie(0);
	cin >> n >> m;

	for (int i = 1;i <= n;++i) cin >> a[i] >> s[i] >> p[i];
	for (int i = 1;i <= m;++i) cin >> b[i] >> t[i] >> q[i];
	for (int i = 1;i <= n;++i) a[i] += a[i-1];
	for (int i = 1;i <= m;++i) b[i] += b[i-1];
	for (int i = 1;i <= n;++i) 
		c[i] = upper_bound(b, b + m + 1, s[i] - a[i]) - b - 1;
	for (int i = 1;i <= m;++i)
		d[i] = upper_bound(a, a + n + 1, t[i] - b[i]) - a - 1;

	set<int> alive;
//	for (int i = 1;i <= m;++i) {
//		alive.insert(i);
//	}
	// w[i] = diff_i - u[i]
	// should be zero at the beginning
	vector<ll> w(m + 10);

	// at this time, it becomes zero
	vector<vector<int>> chg(n + 2);

	for (int i = 1;i <= m;++i) {
		if (d[i] < 0) {
			q[i] = 0;
		} else if (d[i] == n) {
			w[0] += q[i];
		} else chg[ d[i]+1 ].pb(i);
	}
	
	auto upd = [&](int id) {
		while (1 <= id && id <= m) {
			if (w[id] > 0) {
				alive.insert(id);
				break;
			}
			if (w[id] <= 0) {
				alive.erase(id);
				auto it = alive.upper_bound(id);
				ll v = w[id]; w[id] = 0;
				if (v && it != end(alive)) {
					id = *it;
					w[id] += v;
				}
				else break;
			}
		}
	};
	// current dp is 0

	for (int i = 1;i <= n;++i) {

		for (int j : chg[i]) {
			w[j] += q[j];
			alive.insert(j);
		}

		if (c[i] >= 0) {
			w[0] += p[i];
			w[c[i]+1] -= p[i];
			alive.insert(c[i]+1);
		}
		//for (int j = m;j >= 1;--j) upd(j);

		for (int j : chg[i])
			upd(j);
		upd(c[i]+1);
//
//		vector<ll> val(w);
//		for (int j = 1;j <= m;++j) {
//			if (i <= d[j]) val[j] += q[j];
//		}
//		for (int j = 1;j <= m;++j)
//			val[j] += val[j-1];

		//sort(AI(chg[i]));

	}

	ll res = 0 ;
	for (int i = 0;i <= m;++i) res += w[i];

	cout << res << '\n';
	//cout << accumulate(begin(w), begin(w) + m + 1, 0ll) << '\n';

//	//return 0;
//
//	for (int i = 0;i <= n;++i) for (int j = 0;j <= m;++j)
//		dp[i][j] = -inf;
//
//	dp[0][0] = 0;
//
//	DE("dp2d");
//	for (int i = 0;i <= n;++i) {
//
//		for (int j = 1;j <= m;++j) {
//			chmax(dp[i][j], dp[i][j-1] + (i <= d[j] ? q[j] : 0));
//		}
//		DE(i);
//		debug(dp[i], dp[i] + m + 1);
//
//		for (int j = 0;j <= c[i+1];++j)
//			dp[i+1][j] = dp[i][j] + p[i+1];
//		for (int j = c[i+1]+1;j <= m;++j)
//			dp[i+1][j] = dp[i][j];
//
//	}

	//cout << dp[n][m] << '\n';
}
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 31292 KB Output is correct
2 Correct 235 ms 22364 KB Output is correct
3 Correct 198 ms 19048 KB Output is correct
4 Correct 290 ms 28100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 249 ms 21632 KB Output is correct
7 Correct 93 ms 8140 KB Output is correct
8 Correct 104 ms 11224 KB Output is correct
9 Correct 200 ms 19156 KB Output is correct
10 Correct 242 ms 25516 KB Output is correct
11 Correct 151 ms 19068 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 199 ms 19136 KB Output is correct
25 Correct 296 ms 39976 KB Output is correct
26 Correct 196 ms 29768 KB Output is correct
27 Correct 301 ms 45380 KB Output is correct
28 Correct 245 ms 31340 KB Output is correct
29 Correct 179 ms 30404 KB Output is correct
30 Correct 394 ms 33860 KB Output is correct
31 Correct 126 ms 18496 KB Output is correct
32 Correct 94 ms 16464 KB Output is correct
33 Correct 288 ms 31756 KB Output is correct
34 Correct 355 ms 35888 KB Output is correct
35 Correct 366 ms 27320 KB Output is correct
36 Correct 358 ms 27332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 199 ms 19136 KB Output is correct
25 Correct 296 ms 39976 KB Output is correct
26 Correct 196 ms 29768 KB Output is correct
27 Correct 301 ms 45380 KB Output is correct
28 Correct 245 ms 31340 KB Output is correct
29 Correct 179 ms 30404 KB Output is correct
30 Correct 394 ms 33860 KB Output is correct
31 Correct 126 ms 18496 KB Output is correct
32 Correct 94 ms 16464 KB Output is correct
33 Correct 288 ms 31756 KB Output is correct
34 Correct 355 ms 35888 KB Output is correct
35 Correct 366 ms 27320 KB Output is correct
36 Correct 358 ms 27332 KB Output is correct
37 Correct 261 ms 32752 KB Output is correct
38 Correct 363 ms 48420 KB Output is correct
39 Correct 387 ms 45796 KB Output is correct
40 Correct 230 ms 36536 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 470 ms 36996 KB Output is correct
43 Correct 316 ms 34596 KB Output is correct
44 Correct 418 ms 38804 KB Output is correct
45 Correct 391 ms 30532 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 2 ms 460 KB Output is correct
18 Correct 4 ms 588 KB Output is correct
19 Correct 3 ms 588 KB Output is correct
20 Correct 3 ms 460 KB Output is correct
21 Correct 3 ms 588 KB Output is correct
22 Correct 3 ms 588 KB Output is correct
23 Correct 3 ms 588 KB Output is correct
24 Correct 199 ms 19136 KB Output is correct
25 Correct 296 ms 39976 KB Output is correct
26 Correct 196 ms 29768 KB Output is correct
27 Correct 301 ms 45380 KB Output is correct
28 Correct 245 ms 31340 KB Output is correct
29 Correct 179 ms 30404 KB Output is correct
30 Correct 394 ms 33860 KB Output is correct
31 Correct 126 ms 18496 KB Output is correct
32 Correct 94 ms 16464 KB Output is correct
33 Correct 288 ms 31756 KB Output is correct
34 Correct 355 ms 35888 KB Output is correct
35 Correct 366 ms 27320 KB Output is correct
36 Correct 358 ms 27332 KB Output is correct
37 Correct 261 ms 32752 KB Output is correct
38 Correct 363 ms 48420 KB Output is correct
39 Correct 387 ms 45796 KB Output is correct
40 Correct 230 ms 36536 KB Output is correct
41 Correct 1 ms 332 KB Output is correct
42 Correct 470 ms 36996 KB Output is correct
43 Correct 316 ms 34596 KB Output is correct
44 Correct 418 ms 38804 KB Output is correct
45 Correct 391 ms 30532 KB Output is correct
46 Correct 1133 ms 164292 KB Output is correct
47 Correct 1871 ms 242556 KB Output is correct
48 Correct 2268 ms 228884 KB Output is correct
49 Correct 1124 ms 181960 KB Output is correct
50 Correct 2997 ms 184072 KB Output is correct
51 Correct 2115 ms 169492 KB Output is correct
52 Correct 2632 ms 187816 KB Output is correct
53 Correct 2901 ms 152460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 31292 KB Output is correct
2 Correct 235 ms 22364 KB Output is correct
3 Correct 198 ms 19048 KB Output is correct
4 Correct 290 ms 28100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 249 ms 21632 KB Output is correct
7 Correct 93 ms 8140 KB Output is correct
8 Correct 104 ms 11224 KB Output is correct
9 Correct 200 ms 19156 KB Output is correct
10 Correct 242 ms 25516 KB Output is correct
11 Correct 151 ms 19068 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 4 ms 588 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
33 Correct 3 ms 588 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 199 ms 19136 KB Output is correct
36 Correct 296 ms 39976 KB Output is correct
37 Correct 196 ms 29768 KB Output is correct
38 Correct 301 ms 45380 KB Output is correct
39 Correct 245 ms 31340 KB Output is correct
40 Correct 179 ms 30404 KB Output is correct
41 Correct 394 ms 33860 KB Output is correct
42 Correct 126 ms 18496 KB Output is correct
43 Correct 94 ms 16464 KB Output is correct
44 Correct 288 ms 31756 KB Output is correct
45 Correct 355 ms 35888 KB Output is correct
46 Correct 366 ms 27320 KB Output is correct
47 Correct 358 ms 27332 KB Output is correct
48 Correct 261 ms 32752 KB Output is correct
49 Correct 363 ms 48420 KB Output is correct
50 Correct 387 ms 45796 KB Output is correct
51 Correct 230 ms 36536 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 470 ms 36996 KB Output is correct
54 Correct 316 ms 34596 KB Output is correct
55 Correct 418 ms 38804 KB Output is correct
56 Correct 391 ms 30532 KB Output is correct
57 Correct 314 ms 42632 KB Output is correct
58 Correct 297 ms 39560 KB Output is correct
59 Correct 232 ms 37452 KB Output is correct
60 Correct 420 ms 46800 KB Output is correct
61 Correct 316 ms 33860 KB Output is correct
62 Correct 1 ms 332 KB Output is correct
63 Correct 459 ms 37080 KB Output is correct
64 Correct 399 ms 34768 KB Output is correct
65 Correct 391 ms 35364 KB Output is correct
66 Correct 448 ms 30716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 310 ms 31292 KB Output is correct
2 Correct 235 ms 22364 KB Output is correct
3 Correct 198 ms 19048 KB Output is correct
4 Correct 290 ms 28100 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 249 ms 21632 KB Output is correct
7 Correct 93 ms 8140 KB Output is correct
8 Correct 104 ms 11224 KB Output is correct
9 Correct 200 ms 19156 KB Output is correct
10 Correct 242 ms 25516 KB Output is correct
11 Correct 151 ms 19068 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 2 ms 332 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 2 ms 460 KB Output is correct
29 Correct 4 ms 588 KB Output is correct
30 Correct 3 ms 588 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 3 ms 588 KB Output is correct
33 Correct 3 ms 588 KB Output is correct
34 Correct 3 ms 588 KB Output is correct
35 Correct 199 ms 19136 KB Output is correct
36 Correct 296 ms 39976 KB Output is correct
37 Correct 196 ms 29768 KB Output is correct
38 Correct 301 ms 45380 KB Output is correct
39 Correct 245 ms 31340 KB Output is correct
40 Correct 179 ms 30404 KB Output is correct
41 Correct 394 ms 33860 KB Output is correct
42 Correct 126 ms 18496 KB Output is correct
43 Correct 94 ms 16464 KB Output is correct
44 Correct 288 ms 31756 KB Output is correct
45 Correct 355 ms 35888 KB Output is correct
46 Correct 366 ms 27320 KB Output is correct
47 Correct 358 ms 27332 KB Output is correct
48 Correct 261 ms 32752 KB Output is correct
49 Correct 363 ms 48420 KB Output is correct
50 Correct 387 ms 45796 KB Output is correct
51 Correct 230 ms 36536 KB Output is correct
52 Correct 1 ms 332 KB Output is correct
53 Correct 470 ms 36996 KB Output is correct
54 Correct 316 ms 34596 KB Output is correct
55 Correct 418 ms 38804 KB Output is correct
56 Correct 391 ms 30532 KB Output is correct
57 Correct 1133 ms 164292 KB Output is correct
58 Correct 1871 ms 242556 KB Output is correct
59 Correct 2268 ms 228884 KB Output is correct
60 Correct 1124 ms 181960 KB Output is correct
61 Correct 2997 ms 184072 KB Output is correct
62 Correct 2115 ms 169492 KB Output is correct
63 Correct 2632 ms 187816 KB Output is correct
64 Correct 2901 ms 152460 KB Output is correct
65 Correct 314 ms 42632 KB Output is correct
66 Correct 297 ms 39560 KB Output is correct
67 Correct 232 ms 37452 KB Output is correct
68 Correct 420 ms 46800 KB Output is correct
69 Correct 316 ms 33860 KB Output is correct
70 Correct 1 ms 332 KB Output is correct
71 Correct 459 ms 37080 KB Output is correct
72 Correct 399 ms 34768 KB Output is correct
73 Correct 391 ms 35364 KB Output is correct
74 Correct 448 ms 30716 KB Output is correct
75 Correct 1633 ms 212272 KB Output is correct
76 Correct 1255 ms 197016 KB Output is correct
77 Correct 1167 ms 182192 KB Output is correct
78 Correct 2221 ms 223456 KB Output is correct
79 Correct 3058 ms 183492 KB Output is correct
80 Correct 2054 ms 166636 KB Output is correct
81 Correct 2333 ms 165516 KB Output is correct
82 Correct 2790 ms 149944 KB Output is correct
83 Correct 2894 ms 167928 KB Output is correct