답안 #477556

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
477556 2021-10-02T15:36:34 Z cheissmart Two Dishes (JOI19_dishes) C++14
10 / 100
10000 ms 50960 KB
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define MP make_pair
#define EB emplace_back
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;

string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
	cerr << to_string(h);
	if(sizeof ...(t)) cerr << ", ";
	DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif

const int INF = 1e9 + 7, N = 1e6 + 7;

int p[N], q[N];
ll a[N], b[N], s[N], t[N];
V<pi> G[N];

signed main()
{
	IO_OP;
	
	int n, m;
	cin >> n >> m;
	for(int i = 1; i <= n; i++) {
		cin >> a[i] >> s[i] >> p[i];
		a[i] += a[i - 1];
	}
	for(int i = 1; i <= m; i++) {
		cin >> b[i] >> t[i] >> q[i];
		b[i] += b[i - 1];
	}
	ll ans = 0;
	for(int i = 1; i <= n; i++) {
		/*
		a[i] + b[j] <= s[i]
		b[j] <= s[i] - a[i]
		*/
		int j = int(upper_bound(b, b + m + 1, s[i] - a[i]) - b);
		if(!j) continue;
		// if(i-th a before j-th b) ans += p[i]
		G[i].EB(j, p[i]);
	}
	for(int j = 1; j <= m; j++) {
		/*
		a[i] + b[j] <= t[j]
		a[i] <= t[j] - b[j]
		*/
		int i = int(upper_bound(a, a + n + 1, t[j] - b[j]) - a);
		if(!i) continue;
		// original: if(j-th b before i-th a) ans += q[j]
		ans += q[j];
		// now: if(i-th a before j-th b) ans += -q[j]
		G[i].EB(j, -q[j]);
	}
	// map<int, ll> mp;
	V<ll> mp(m + 1);
	for(int i = 1; i <= n; i++) {
		sort(ALL(G[i]), greater<pi>());
		for(auto [j, v] : G[i]) {
			// 0 ~ j - 1 add v
			for(int k = 0; k < j; k++)
				mp[k] += v;
			// ans += v;
			// mp[j] -= v;
			// if(mp[j] < 0) {
			// 	auto it = mp.find(j);
			// 	assert(it -> S < 0);
			// 	while(it -> S < 0) {
			// 		it++;
			// 		if(it != mp.end()) {
			// 			mp[it -> F] += mp[prev(it) -> F];
			// 			mp.erase(prev(it));
			// 		} else {
			// 			mp.erase(prev(it));
			// 			break;
			// 		}
			// 	}
			// }
		}
		for(int k = 1; k <= m; k++)
			mp[k] = max(mp[k], mp[k - 1]);
	}
	ans += mp[m];
	// for(auto [x, y]:mp) {
	// 	ans += y;
	// 	assert(y >= 0);
	// }
	cout << ans << '\n';

}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:77:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   77 |   for(auto [j, v] : G[i]) {
      |            ^
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10091 ms 40584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 14 ms 23732 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 12 ms 23844 KB Output is correct
9 Correct 14 ms 23760 KB Output is correct
10 Correct 14 ms 23768 KB Output is correct
11 Correct 12 ms 23832 KB Output is correct
12 Correct 12 ms 23776 KB Output is correct
13 Correct 13 ms 23804 KB Output is correct
14 Correct 12 ms 23760 KB Output is correct
15 Correct 13 ms 23800 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 14 ms 23732 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 12 ms 23844 KB Output is correct
9 Correct 14 ms 23760 KB Output is correct
10 Correct 14 ms 23768 KB Output is correct
11 Correct 12 ms 23832 KB Output is correct
12 Correct 12 ms 23776 KB Output is correct
13 Correct 13 ms 23804 KB Output is correct
14 Correct 12 ms 23760 KB Output is correct
15 Correct 13 ms 23800 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 29 ms 24016 KB Output is correct
18 Correct 33 ms 24080 KB Output is correct
19 Correct 33 ms 24016 KB Output is correct
20 Correct 30 ms 24180 KB Output is correct
21 Correct 33 ms 24012 KB Output is correct
22 Correct 31 ms 23944 KB Output is correct
23 Correct 31 ms 24016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 14 ms 23732 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 12 ms 23844 KB Output is correct
9 Correct 14 ms 23760 KB Output is correct
10 Correct 14 ms 23768 KB Output is correct
11 Correct 12 ms 23832 KB Output is correct
12 Correct 12 ms 23776 KB Output is correct
13 Correct 13 ms 23804 KB Output is correct
14 Correct 12 ms 23760 KB Output is correct
15 Correct 13 ms 23800 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 29 ms 24016 KB Output is correct
18 Correct 33 ms 24080 KB Output is correct
19 Correct 33 ms 24016 KB Output is correct
20 Correct 30 ms 24180 KB Output is correct
21 Correct 33 ms 24012 KB Output is correct
22 Correct 31 ms 23944 KB Output is correct
23 Correct 31 ms 24016 KB Output is correct
24 Execution timed out 10050 ms 50960 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 14 ms 23732 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 12 ms 23844 KB Output is correct
9 Correct 14 ms 23760 KB Output is correct
10 Correct 14 ms 23768 KB Output is correct
11 Correct 12 ms 23832 KB Output is correct
12 Correct 12 ms 23776 KB Output is correct
13 Correct 13 ms 23804 KB Output is correct
14 Correct 12 ms 23760 KB Output is correct
15 Correct 13 ms 23800 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 29 ms 24016 KB Output is correct
18 Correct 33 ms 24080 KB Output is correct
19 Correct 33 ms 24016 KB Output is correct
20 Correct 30 ms 24180 KB Output is correct
21 Correct 33 ms 24012 KB Output is correct
22 Correct 31 ms 23944 KB Output is correct
23 Correct 31 ms 24016 KB Output is correct
24 Execution timed out 10050 ms 50960 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 12 ms 23792 KB Output is correct
3 Correct 12 ms 23760 KB Output is correct
4 Correct 14 ms 23732 KB Output is correct
5 Correct 12 ms 23816 KB Output is correct
6 Correct 16 ms 23764 KB Output is correct
7 Correct 15 ms 23796 KB Output is correct
8 Correct 12 ms 23844 KB Output is correct
9 Correct 14 ms 23760 KB Output is correct
10 Correct 14 ms 23768 KB Output is correct
11 Correct 12 ms 23832 KB Output is correct
12 Correct 12 ms 23776 KB Output is correct
13 Correct 13 ms 23804 KB Output is correct
14 Correct 12 ms 23760 KB Output is correct
15 Correct 13 ms 23800 KB Output is correct
16 Correct 13 ms 23808 KB Output is correct
17 Correct 29 ms 24016 KB Output is correct
18 Correct 33 ms 24080 KB Output is correct
19 Correct 33 ms 24016 KB Output is correct
20 Correct 30 ms 24180 KB Output is correct
21 Correct 33 ms 24012 KB Output is correct
22 Correct 31 ms 23944 KB Output is correct
23 Correct 31 ms 24016 KB Output is correct
24 Execution timed out 10050 ms 50960 KB Time limit exceeded
25 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10091 ms 40584 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 10091 ms 40584 KB Time limit exceeded
2 Halted 0 ms 0 KB -