Submission #477559

# Submission time Handle Problem Language Result Execution time Memory
477559 2021-10-02T15:47:03 Z cheissmart Two Dishes (JOI19_dishes) C++14
74 / 100
3114 ms 180356 KB
#include <bits/stdc++.h>
#define int ll
#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;
	for(int i = 1; i <= n; i++) {
		sort(ALL(G[i]), [&](pi x, pi y) {
			return x.S < y.S;
		});
		for(auto [j, v] : G[i]) {
			// 0 ~ j - 1 add v
			ans += v;
			mp[j] -= v;
			if(mp[j] < 0) {
				auto it = mp.find(j);
				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(auto [x, y]:mp)
		ans += y;
	cout << ans << '\n';

}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:79:12: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   79 |   for(auto [j, v] : G[i]) {
      |            ^
dishes.cpp:99:11: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   99 |  for(auto [x, y]:mp)
      |           ^
# Verdict Execution time Memory Grader output
1 Correct 274 ms 54236 KB Output is correct
2 Correct 254 ms 43728 KB Output is correct
3 Correct 212 ms 43696 KB Output is correct
4 Correct 298 ms 46528 KB Output is correct
5 Correct 14 ms 23884 KB Output is correct
6 Correct 261 ms 43036 KB Output is correct
7 Correct 125 ms 32700 KB Output is correct
8 Correct 131 ms 34756 KB Output is correct
9 Correct 225 ms 43716 KB Output is correct
10 Correct 217 ms 42704 KB Output is correct
11 Correct 155 ms 43668 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23956 KB Output is correct
2 Correct 14 ms 23732 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23832 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 19 ms 23844 KB Output is correct
7 Correct 17 ms 23800 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 14 ms 23740 KB Output is correct
11 Correct 15 ms 23844 KB Output is correct
12 Correct 16 ms 23756 KB Output is correct
13 Correct 13 ms 23756 KB Output is correct
14 Correct 13 ms 23776 KB Output is correct
15 Correct 17 ms 23844 KB Output is correct
16 Correct 17 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23956 KB Output is correct
2 Correct 14 ms 23732 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23832 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 19 ms 23844 KB Output is correct
7 Correct 17 ms 23800 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 14 ms 23740 KB Output is correct
11 Correct 15 ms 23844 KB Output is correct
12 Correct 16 ms 23756 KB Output is correct
13 Correct 13 ms 23756 KB Output is correct
14 Correct 13 ms 23776 KB Output is correct
15 Correct 17 ms 23844 KB Output is correct
16 Correct 17 ms 23756 KB Output is correct
17 Correct 19 ms 24028 KB Output is correct
18 Correct 16 ms 24128 KB Output is correct
19 Correct 19 ms 24044 KB Output is correct
20 Correct 17 ms 23964 KB Output is correct
21 Correct 19 ms 24032 KB Output is correct
22 Correct 17 ms 24012 KB Output is correct
23 Correct 17 ms 24012 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23956 KB Output is correct
2 Correct 14 ms 23732 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23832 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 19 ms 23844 KB Output is correct
7 Correct 17 ms 23800 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 14 ms 23740 KB Output is correct
11 Correct 15 ms 23844 KB Output is correct
12 Correct 16 ms 23756 KB Output is correct
13 Correct 13 ms 23756 KB Output is correct
14 Correct 13 ms 23776 KB Output is correct
15 Correct 17 ms 23844 KB Output is correct
16 Correct 17 ms 23756 KB Output is correct
17 Correct 19 ms 24028 KB Output is correct
18 Correct 16 ms 24128 KB Output is correct
19 Correct 19 ms 24044 KB Output is correct
20 Correct 17 ms 23964 KB Output is correct
21 Correct 19 ms 24032 KB Output is correct
22 Correct 17 ms 24012 KB Output is correct
23 Correct 17 ms 24012 KB Output is correct
24 Correct 200 ms 41636 KB Output is correct
25 Correct 256 ms 52004 KB Output is correct
26 Correct 234 ms 41616 KB Output is correct
27 Correct 377 ms 53572 KB Output is correct
28 Correct 283 ms 42392 KB Output is correct
29 Correct 199 ms 43700 KB Output is correct
30 Correct 498 ms 44776 KB Output is correct
31 Correct 117 ms 37920 KB Output is correct
32 Correct 108 ms 34692 KB Output is correct
33 Correct 348 ms 38884 KB Output is correct
34 Correct 396 ms 48820 KB Output is correct
35 Correct 463 ms 44948 KB Output is correct
36 Correct 431 ms 44644 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23956 KB Output is correct
2 Correct 14 ms 23732 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23832 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 19 ms 23844 KB Output is correct
7 Correct 17 ms 23800 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 14 ms 23740 KB Output is correct
11 Correct 15 ms 23844 KB Output is correct
12 Correct 16 ms 23756 KB Output is correct
13 Correct 13 ms 23756 KB Output is correct
14 Correct 13 ms 23776 KB Output is correct
15 Correct 17 ms 23844 KB Output is correct
16 Correct 17 ms 23756 KB Output is correct
17 Correct 19 ms 24028 KB Output is correct
18 Correct 16 ms 24128 KB Output is correct
19 Correct 19 ms 24044 KB Output is correct
20 Correct 17 ms 23964 KB Output is correct
21 Correct 19 ms 24032 KB Output is correct
22 Correct 17 ms 24012 KB Output is correct
23 Correct 17 ms 24012 KB Output is correct
24 Correct 200 ms 41636 KB Output is correct
25 Correct 256 ms 52004 KB Output is correct
26 Correct 234 ms 41616 KB Output is correct
27 Correct 377 ms 53572 KB Output is correct
28 Correct 283 ms 42392 KB Output is correct
29 Correct 199 ms 43700 KB Output is correct
30 Correct 498 ms 44776 KB Output is correct
31 Correct 117 ms 37920 KB Output is correct
32 Correct 108 ms 34692 KB Output is correct
33 Correct 348 ms 38884 KB Output is correct
34 Correct 396 ms 48820 KB Output is correct
35 Correct 463 ms 44948 KB Output is correct
36 Correct 431 ms 44644 KB Output is correct
37 Correct 218 ms 41656 KB Output is correct
38 Correct 344 ms 53468 KB Output is correct
39 Correct 403 ms 55060 KB Output is correct
40 Correct 239 ms 42592 KB Output is correct
41 Correct 14 ms 23836 KB Output is correct
42 Correct 516 ms 44868 KB Output is correct
43 Correct 338 ms 38752 KB Output is correct
44 Correct 441 ms 48800 KB Output is correct
45 Correct 474 ms 44868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23956 KB Output is correct
2 Correct 14 ms 23732 KB Output is correct
3 Correct 14 ms 23756 KB Output is correct
4 Correct 14 ms 23832 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 19 ms 23844 KB Output is correct
7 Correct 17 ms 23800 KB Output is correct
8 Correct 17 ms 23788 KB Output is correct
9 Correct 16 ms 23756 KB Output is correct
10 Correct 14 ms 23740 KB Output is correct
11 Correct 15 ms 23844 KB Output is correct
12 Correct 16 ms 23756 KB Output is correct
13 Correct 13 ms 23756 KB Output is correct
14 Correct 13 ms 23776 KB Output is correct
15 Correct 17 ms 23844 KB Output is correct
16 Correct 17 ms 23756 KB Output is correct
17 Correct 19 ms 24028 KB Output is correct
18 Correct 16 ms 24128 KB Output is correct
19 Correct 19 ms 24044 KB Output is correct
20 Correct 17 ms 23964 KB Output is correct
21 Correct 19 ms 24032 KB Output is correct
22 Correct 17 ms 24012 KB Output is correct
23 Correct 17 ms 24012 KB Output is correct
24 Correct 200 ms 41636 KB Output is correct
25 Correct 256 ms 52004 KB Output is correct
26 Correct 234 ms 41616 KB Output is correct
27 Correct 377 ms 53572 KB Output is correct
28 Correct 283 ms 42392 KB Output is correct
29 Correct 199 ms 43700 KB Output is correct
30 Correct 498 ms 44776 KB Output is correct
31 Correct 117 ms 37920 KB Output is correct
32 Correct 108 ms 34692 KB Output is correct
33 Correct 348 ms 38884 KB Output is correct
34 Correct 396 ms 48820 KB Output is correct
35 Correct 463 ms 44948 KB Output is correct
36 Correct 431 ms 44644 KB Output is correct
37 Correct 218 ms 41656 KB Output is correct
38 Correct 344 ms 53468 KB Output is correct
39 Correct 403 ms 55060 KB Output is correct
40 Correct 239 ms 42592 KB Output is correct
41 Correct 14 ms 23836 KB Output is correct
42 Correct 516 ms 44868 KB Output is correct
43 Correct 338 ms 38752 KB Output is correct
44 Correct 441 ms 48800 KB Output is correct
45 Correct 474 ms 44868 KB Output is correct
46 Correct 1113 ms 110400 KB Output is correct
47 Correct 2013 ms 172528 KB Output is correct
48 Correct 2306 ms 180356 KB Output is correct
49 Correct 1055 ms 117692 KB Output is correct
50 Correct 3114 ms 129232 KB Output is correct
51 Correct 1759 ms 96672 KB Output is correct
52 Correct 2505 ms 145644 KB Output is correct
53 Correct 2738 ms 128024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 274 ms 54236 KB Output is correct
2 Correct 254 ms 43728 KB Output is correct
3 Correct 212 ms 43696 KB Output is correct
4 Correct 298 ms 46528 KB Output is correct
5 Correct 14 ms 23884 KB Output is correct
6 Correct 261 ms 43036 KB Output is correct
7 Correct 125 ms 32700 KB Output is correct
8 Correct 131 ms 34756 KB Output is correct
9 Correct 225 ms 43716 KB Output is correct
10 Correct 217 ms 42704 KB Output is correct
11 Correct 155 ms 43668 KB Output is correct
12 Correct 14 ms 23956 KB Output is correct
13 Correct 14 ms 23732 KB Output is correct
14 Correct 14 ms 23756 KB Output is correct
15 Correct 14 ms 23832 KB Output is correct
16 Correct 14 ms 23756 KB Output is correct
17 Correct 19 ms 23844 KB Output is correct
18 Correct 17 ms 23800 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 16 ms 23756 KB Output is correct
21 Correct 14 ms 23740 KB Output is correct
22 Correct 15 ms 23844 KB Output is correct
23 Correct 16 ms 23756 KB Output is correct
24 Correct 13 ms 23756 KB Output is correct
25 Correct 13 ms 23776 KB Output is correct
26 Correct 17 ms 23844 KB Output is correct
27 Correct 17 ms 23756 KB Output is correct
28 Correct 19 ms 24028 KB Output is correct
29 Correct 16 ms 24128 KB Output is correct
30 Correct 19 ms 24044 KB Output is correct
31 Correct 17 ms 23964 KB Output is correct
32 Correct 19 ms 24032 KB Output is correct
33 Correct 17 ms 24012 KB Output is correct
34 Correct 17 ms 24012 KB Output is correct
35 Correct 200 ms 41636 KB Output is correct
36 Correct 256 ms 52004 KB Output is correct
37 Correct 234 ms 41616 KB Output is correct
38 Correct 377 ms 53572 KB Output is correct
39 Correct 283 ms 42392 KB Output is correct
40 Correct 199 ms 43700 KB Output is correct
41 Correct 498 ms 44776 KB Output is correct
42 Correct 117 ms 37920 KB Output is correct
43 Correct 108 ms 34692 KB Output is correct
44 Correct 348 ms 38884 KB Output is correct
45 Correct 396 ms 48820 KB Output is correct
46 Correct 463 ms 44948 KB Output is correct
47 Correct 431 ms 44644 KB Output is correct
48 Correct 218 ms 41656 KB Output is correct
49 Correct 344 ms 53468 KB Output is correct
50 Correct 403 ms 55060 KB Output is correct
51 Correct 239 ms 42592 KB Output is correct
52 Correct 14 ms 23836 KB Output is correct
53 Correct 516 ms 44868 KB Output is correct
54 Correct 338 ms 38752 KB Output is correct
55 Correct 441 ms 48800 KB Output is correct
56 Correct 474 ms 44868 KB Output is correct
57 Correct 313 ms 53640 KB Output is correct
58 Correct 232 ms 41020 KB Output is correct
59 Correct 242 ms 42592 KB Output is correct
60 Correct 387 ms 55108 KB Output is correct
61 Correct 689 ms 57416 KB Output is correct
62 Correct 14 ms 23792 KB Output is correct
63 Correct 543 ms 44788 KB Output is correct
64 Correct 326 ms 38760 KB Output is correct
65 Incorrect 446 ms 44324 KB Output isn't correct
66 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 274 ms 54236 KB Output is correct
2 Correct 254 ms 43728 KB Output is correct
3 Correct 212 ms 43696 KB Output is correct
4 Correct 298 ms 46528 KB Output is correct
5 Correct 14 ms 23884 KB Output is correct
6 Correct 261 ms 43036 KB Output is correct
7 Correct 125 ms 32700 KB Output is correct
8 Correct 131 ms 34756 KB Output is correct
9 Correct 225 ms 43716 KB Output is correct
10 Correct 217 ms 42704 KB Output is correct
11 Correct 155 ms 43668 KB Output is correct
12 Correct 14 ms 23956 KB Output is correct
13 Correct 14 ms 23732 KB Output is correct
14 Correct 14 ms 23756 KB Output is correct
15 Correct 14 ms 23832 KB Output is correct
16 Correct 14 ms 23756 KB Output is correct
17 Correct 19 ms 23844 KB Output is correct
18 Correct 17 ms 23800 KB Output is correct
19 Correct 17 ms 23788 KB Output is correct
20 Correct 16 ms 23756 KB Output is correct
21 Correct 14 ms 23740 KB Output is correct
22 Correct 15 ms 23844 KB Output is correct
23 Correct 16 ms 23756 KB Output is correct
24 Correct 13 ms 23756 KB Output is correct
25 Correct 13 ms 23776 KB Output is correct
26 Correct 17 ms 23844 KB Output is correct
27 Correct 17 ms 23756 KB Output is correct
28 Correct 19 ms 24028 KB Output is correct
29 Correct 16 ms 24128 KB Output is correct
30 Correct 19 ms 24044 KB Output is correct
31 Correct 17 ms 23964 KB Output is correct
32 Correct 19 ms 24032 KB Output is correct
33 Correct 17 ms 24012 KB Output is correct
34 Correct 17 ms 24012 KB Output is correct
35 Correct 200 ms 41636 KB Output is correct
36 Correct 256 ms 52004 KB Output is correct
37 Correct 234 ms 41616 KB Output is correct
38 Correct 377 ms 53572 KB Output is correct
39 Correct 283 ms 42392 KB Output is correct
40 Correct 199 ms 43700 KB Output is correct
41 Correct 498 ms 44776 KB Output is correct
42 Correct 117 ms 37920 KB Output is correct
43 Correct 108 ms 34692 KB Output is correct
44 Correct 348 ms 38884 KB Output is correct
45 Correct 396 ms 48820 KB Output is correct
46 Correct 463 ms 44948 KB Output is correct
47 Correct 431 ms 44644 KB Output is correct
48 Correct 218 ms 41656 KB Output is correct
49 Correct 344 ms 53468 KB Output is correct
50 Correct 403 ms 55060 KB Output is correct
51 Correct 239 ms 42592 KB Output is correct
52 Correct 14 ms 23836 KB Output is correct
53 Correct 516 ms 44868 KB Output is correct
54 Correct 338 ms 38752 KB Output is correct
55 Correct 441 ms 48800 KB Output is correct
56 Correct 474 ms 44868 KB Output is correct
57 Correct 1113 ms 110400 KB Output is correct
58 Correct 2013 ms 172528 KB Output is correct
59 Correct 2306 ms 180356 KB Output is correct
60 Correct 1055 ms 117692 KB Output is correct
61 Correct 3114 ms 129232 KB Output is correct
62 Correct 1759 ms 96672 KB Output is correct
63 Correct 2505 ms 145644 KB Output is correct
64 Correct 2738 ms 128024 KB Output is correct
65 Correct 313 ms 53640 KB Output is correct
66 Correct 232 ms 41020 KB Output is correct
67 Correct 242 ms 42592 KB Output is correct
68 Correct 387 ms 55108 KB Output is correct
69 Correct 689 ms 57416 KB Output is correct
70 Correct 14 ms 23792 KB Output is correct
71 Correct 543 ms 44788 KB Output is correct
72 Correct 326 ms 38760 KB Output is correct
73 Incorrect 446 ms 44324 KB Output isn't correct
74 Halted 0 ms 0 KB -