Submission #426456

# Submission time Handle Problem Language Result Execution time Memory
426456 2021-06-14T04:14:16 Z Kevin_Zhang_TW Two Dishes (JOI19_dishes) C++17
10 / 100
263 ms 49168 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

	assert(n < MAX_M);

	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';
}
# Verdict Execution time Memory Grader output
1 Runtime error 263 ms 46296 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 324 KB Output is correct
7 Correct 1 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
# Verdict Execution time Memory 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 324 KB Output is correct
7 Correct 1 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 30 ms 668 KB Output is correct
18 Correct 171 ms 752 KB Output is correct
19 Correct 104 ms 712 KB Output is correct
20 Correct 74 ms 588 KB Output is correct
21 Correct 87 ms 684 KB Output is correct
22 Correct 85 ms 588 KB Output is correct
23 Correct 91 ms 620 KB Output is correct
# Verdict Execution time Memory 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 324 KB Output is correct
7 Correct 1 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 30 ms 668 KB Output is correct
18 Correct 171 ms 752 KB Output is correct
19 Correct 104 ms 712 KB Output is correct
20 Correct 74 ms 588 KB Output is correct
21 Correct 87 ms 684 KB Output is correct
22 Correct 85 ms 588 KB Output is correct
23 Correct 91 ms 620 KB Output is correct
24 Runtime error 195 ms 49168 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 324 KB Output is correct
7 Correct 1 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 30 ms 668 KB Output is correct
18 Correct 171 ms 752 KB Output is correct
19 Correct 104 ms 712 KB Output is correct
20 Correct 74 ms 588 KB Output is correct
21 Correct 87 ms 684 KB Output is correct
22 Correct 85 ms 588 KB Output is correct
23 Correct 91 ms 620 KB Output is correct
24 Runtime error 195 ms 49168 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory 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 324 KB Output is correct
7 Correct 1 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 30 ms 668 KB Output is correct
18 Correct 171 ms 752 KB Output is correct
19 Correct 104 ms 712 KB Output is correct
20 Correct 74 ms 588 KB Output is correct
21 Correct 87 ms 684 KB Output is correct
22 Correct 85 ms 588 KB Output is correct
23 Correct 91 ms 620 KB Output is correct
24 Runtime error 195 ms 49168 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 263 ms 46296 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 263 ms 46296 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -