Submission #102083

# Submission time Handle Problem Language Result Execution time Memory
102083 2019-03-22T07:15:48 Z ainta Two Dishes (JOI19_dishes) C++17
100 / 100
8164 ms 217548 KB
#include<cstdio>
#include<algorithm>
#include<map>
#define N_ 1010000
#define SZ (1<<20)
#define pii pair<int,int>
using namespace std;
struct Input {
	int a;
	long long t, c;
}A[N_], B[N_];
long long SA[N_], SB[N_], res;
int n, m, cnt;
struct Tree {
	long long Mx[SZ + SZ], K[SZ + SZ], INF = 1e18;
	void Add2(int nd, long long x) {
		Mx[nd] += x;
		K[nd] += x;
	}
	void Spread(int nd) {
		Add2(nd * 2, K[nd]);
		Add2(nd * 2 + 1, K[nd]);
		K[nd] = 0;
	}
	void UDT(int nd) {
		Mx[nd] = max(Mx[nd * 2], Mx[nd * 2 + 1]);
	}
	void Add(int nd, int b, int e, int s, int l, long long x) {
		if (s > l)return;
		if (b == s && e == l) {
			Add2(nd, x);
			return;
		}
		Spread(nd);
		int m = (b + e) >> 1;
		if (s <= m)Add(nd * 2, b, m, s, min(m, l), x);
		if (l > m)Add(nd * 2 + 1, m + 1, e, max(m + 1, s), l, x);
		UDT(nd);
	}
	long long Max(int nd, int b, int e, int s, int l) {
		if (s > l)return -INF;
		if (b == s && e == l) return Mx[nd];
		Spread(nd);
		int m = (b + e) >> 1;
		long long r = -INF;
		if (s <= m)r = max(r, Max(nd * 2, b, m, s, min(m, l)));
		if (l > m)r = max(r, Max(nd * 2 + 1, m + 1, e, max(m + 1, s), l));
		return r;
	}
	void Put(int nd, int b, int e, int x, long long y) {
		if (b == e) {
			if (Mx[nd] < y) {
				Mx[nd] = y, K[nd] = y;
			}
			return;
		}
		Spread(nd);
		int m = (b + e) >> 1;
		if (x <= m)Put(nd * 2, b, m, x, y);
		else Put(nd * 2 + 1, m + 1, e, x, y);
		UDT(nd);
	}
}TT;
int main() {
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		scanf("%d%lld%lld", &A[i].a, &A[i].t, &A[i].c);
		SA[i] = SA[i - 1] + A[i].a;
	}
	for (i = 1; i <= m; i++) {
		scanf("%d%lld%lld", &B[i].a, &B[i].t, &B[i].c);
		SB[i] = SB[i - 1] + B[i].a;
	}
	long long ss = 0;
	map<pii, int>Map;
	for (i = 1; i <= n; i++) {
		if (SA[i] > A[i].t) continue;
		if (SA[i] + SB[m] <= A[i].t) {
			ss += A[i].c;
			continue;
		}
		int pv = lower_bound(SB + 1, SB + m + 1, A[i].t - SA[i] + 1) - SB;
		pv--;
		Map[{i - 1, -(pv + 1)}] += A[i].c;
	}
	for (i = 1; i <= m; i++) {
		if (SB[i] > B[i].t) continue;
		if (SB[i] + SA[n] <= B[i].t) {
			ss += B[i].c;
			continue;
		}
		int pv = lower_bound(SA + 1, SA + n + 1, B[i].t - SB[i] + 1) - SA;
		pv--;
		ss += B[i].c;
		Map[{pv, -i}] -= B[i].c;
	}
	for (auto &tp : Map) {
		int x = tp.first.first, y = -tp.first.second, c = tp.second;
		long long t = TT.Max(1, 0, SZ - 1, 0, y - 1);
		TT.Put(1, 0, SZ - 1, y, t);
		TT.Add(1, 0, SZ - 1, 0, y - 1, c);
	}
	printf("%lld\n", TT.Max(1, 0, SZ - 1, 0, SZ - 1) + ss);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:99:7: warning: unused variable 'x' [-Wunused-variable]
   int x = tp.first.first, y = -tp.first.second, c = tp.second;
       ^
dishes.cpp:65:9: warning: unused variable 'j' [-Wunused-variable]
  int i, j;
         ^
dishes.cpp:66:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d%d", &n, &m);
  ~~~~~^~~~~~~~~~~~~~~~
dishes.cpp:68:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%lld", &A[i].a, &A[i].t, &A[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:72:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%lld", &B[i].a, &B[i].t, &B[i].c);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 551 ms 36208 KB Output is correct
2 Correct 506 ms 35152 KB Output is correct
3 Correct 231 ms 15392 KB Output is correct
4 Correct 385 ms 27064 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 420 ms 31324 KB Output is correct
7 Correct 114 ms 9736 KB Output is correct
8 Correct 102 ms 9592 KB Output is correct
9 Correct 210 ms 15388 KB Output is correct
10 Correct 433 ms 34796 KB Output is correct
11 Correct 188 ms 15864 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 7 ms 896 KB Output is correct
19 Correct 10 ms 1024 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 1024 KB Output is correct
23 Correct 10 ms 896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 7 ms 896 KB Output is correct
19 Correct 10 ms 1024 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 1024 KB Output is correct
23 Correct 10 ms 896 KB Output is correct
24 Correct 470 ms 28204 KB Output is correct
25 Correct 398 ms 34268 KB Output is correct
26 Correct 468 ms 34344 KB Output is correct
27 Correct 425 ms 34320 KB Output is correct
28 Correct 453 ms 28120 KB Output is correct
29 Correct 174 ms 15224 KB Output is correct
30 Correct 1138 ms 46024 KB Output is correct
31 Correct 209 ms 22404 KB Output is correct
32 Correct 248 ms 15992 KB Output is correct
33 Correct 670 ms 33780 KB Output is correct
34 Correct 942 ms 40792 KB Output is correct
35 Correct 1084 ms 47196 KB Output is correct
36 Correct 1048 ms 46328 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 7 ms 896 KB Output is correct
19 Correct 10 ms 1024 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 1024 KB Output is correct
23 Correct 10 ms 896 KB Output is correct
24 Correct 470 ms 28204 KB Output is correct
25 Correct 398 ms 34268 KB Output is correct
26 Correct 468 ms 34344 KB Output is correct
27 Correct 425 ms 34320 KB Output is correct
28 Correct 453 ms 28120 KB Output is correct
29 Correct 174 ms 15224 KB Output is correct
30 Correct 1138 ms 46024 KB Output is correct
31 Correct 209 ms 22404 KB Output is correct
32 Correct 248 ms 15992 KB Output is correct
33 Correct 670 ms 33780 KB Output is correct
34 Correct 942 ms 40792 KB Output is correct
35 Correct 1084 ms 47196 KB Output is correct
36 Correct 1048 ms 46328 KB Output is correct
37 Correct 507 ms 34448 KB Output is correct
38 Correct 382 ms 34296 KB Output is correct
39 Correct 469 ms 34296 KB Output is correct
40 Correct 421 ms 34300 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 1167 ms 45988 KB Output is correct
43 Correct 659 ms 33736 KB Output is correct
44 Correct 986 ms 40384 KB Output is correct
45 Correct 1044 ms 46840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 512 KB Output is correct
2 Correct 2 ms 388 KB Output is correct
3 Correct 2 ms 384 KB Output is correct
4 Correct 3 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 3 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 2 ms 512 KB Output is correct
9 Correct 2 ms 512 KB Output is correct
10 Correct 2 ms 512 KB Output is correct
11 Correct 2 ms 512 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 512 KB Output is correct
14 Correct 2 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 3 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 7 ms 896 KB Output is correct
19 Correct 10 ms 1024 KB Output is correct
20 Correct 7 ms 896 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 1024 KB Output is correct
23 Correct 10 ms 896 KB Output is correct
24 Correct 470 ms 28204 KB Output is correct
25 Correct 398 ms 34268 KB Output is correct
26 Correct 468 ms 34344 KB Output is correct
27 Correct 425 ms 34320 KB Output is correct
28 Correct 453 ms 28120 KB Output is correct
29 Correct 174 ms 15224 KB Output is correct
30 Correct 1138 ms 46024 KB Output is correct
31 Correct 209 ms 22404 KB Output is correct
32 Correct 248 ms 15992 KB Output is correct
33 Correct 670 ms 33780 KB Output is correct
34 Correct 942 ms 40792 KB Output is correct
35 Correct 1084 ms 47196 KB Output is correct
36 Correct 1048 ms 46328 KB Output is correct
37 Correct 507 ms 34448 KB Output is correct
38 Correct 382 ms 34296 KB Output is correct
39 Correct 469 ms 34296 KB Output is correct
40 Correct 421 ms 34300 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 1167 ms 45988 KB Output is correct
43 Correct 659 ms 33736 KB Output is correct
44 Correct 986 ms 40384 KB Output is correct
45 Correct 1044 ms 46840 KB Output is correct
46 Correct 2224 ms 157840 KB Output is correct
47 Correct 2292 ms 157712 KB Output is correct
48 Correct 2480 ms 157436 KB Output is correct
49 Correct 2288 ms 157176 KB Output is correct
50 Correct 8164 ms 217548 KB Output is correct
51 Correct 3906 ms 151004 KB Output is correct
52 Correct 5351 ms 173564 KB Output is correct
53 Correct 7241 ms 212716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 36208 KB Output is correct
2 Correct 506 ms 35152 KB Output is correct
3 Correct 231 ms 15392 KB Output is correct
4 Correct 385 ms 27064 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 420 ms 31324 KB Output is correct
7 Correct 114 ms 9736 KB Output is correct
8 Correct 102 ms 9592 KB Output is correct
9 Correct 210 ms 15388 KB Output is correct
10 Correct 433 ms 34796 KB Output is correct
11 Correct 188 ms 15864 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 388 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 896 KB Output is correct
30 Correct 10 ms 1024 KB Output is correct
31 Correct 7 ms 896 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 8 ms 1024 KB Output is correct
34 Correct 10 ms 896 KB Output is correct
35 Correct 470 ms 28204 KB Output is correct
36 Correct 398 ms 34268 KB Output is correct
37 Correct 468 ms 34344 KB Output is correct
38 Correct 425 ms 34320 KB Output is correct
39 Correct 453 ms 28120 KB Output is correct
40 Correct 174 ms 15224 KB Output is correct
41 Correct 1138 ms 46024 KB Output is correct
42 Correct 209 ms 22404 KB Output is correct
43 Correct 248 ms 15992 KB Output is correct
44 Correct 670 ms 33780 KB Output is correct
45 Correct 942 ms 40792 KB Output is correct
46 Correct 1084 ms 47196 KB Output is correct
47 Correct 1048 ms 46328 KB Output is correct
48 Correct 507 ms 34448 KB Output is correct
49 Correct 382 ms 34296 KB Output is correct
50 Correct 469 ms 34296 KB Output is correct
51 Correct 421 ms 34300 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 1167 ms 45988 KB Output is correct
54 Correct 659 ms 33736 KB Output is correct
55 Correct 986 ms 40384 KB Output is correct
56 Correct 1044 ms 46840 KB Output is correct
57 Correct 426 ms 33500 KB Output is correct
58 Correct 463 ms 33452 KB Output is correct
59 Correct 429 ms 33548 KB Output is correct
60 Correct 444 ms 33560 KB Output is correct
61 Correct 1068 ms 46200 KB Output is correct
62 Correct 3 ms 512 KB Output is correct
63 Correct 1260 ms 45156 KB Output is correct
64 Correct 715 ms 32436 KB Output is correct
65 Correct 945 ms 39900 KB Output is correct
66 Correct 1024 ms 44712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 551 ms 36208 KB Output is correct
2 Correct 506 ms 35152 KB Output is correct
3 Correct 231 ms 15392 KB Output is correct
4 Correct 385 ms 27064 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 420 ms 31324 KB Output is correct
7 Correct 114 ms 9736 KB Output is correct
8 Correct 102 ms 9592 KB Output is correct
9 Correct 210 ms 15388 KB Output is correct
10 Correct 433 ms 34796 KB Output is correct
11 Correct 188 ms 15864 KB Output is correct
12 Correct 2 ms 512 KB Output is correct
13 Correct 2 ms 388 KB Output is correct
14 Correct 2 ms 384 KB Output is correct
15 Correct 3 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 3 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 2 ms 512 KB Output is correct
20 Correct 2 ms 512 KB Output is correct
21 Correct 2 ms 512 KB Output is correct
22 Correct 2 ms 512 KB Output is correct
23 Correct 2 ms 512 KB Output is correct
24 Correct 2 ms 512 KB Output is correct
25 Correct 2 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 3 ms 512 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 7 ms 896 KB Output is correct
30 Correct 10 ms 1024 KB Output is correct
31 Correct 7 ms 896 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 8 ms 1024 KB Output is correct
34 Correct 10 ms 896 KB Output is correct
35 Correct 470 ms 28204 KB Output is correct
36 Correct 398 ms 34268 KB Output is correct
37 Correct 468 ms 34344 KB Output is correct
38 Correct 425 ms 34320 KB Output is correct
39 Correct 453 ms 28120 KB Output is correct
40 Correct 174 ms 15224 KB Output is correct
41 Correct 1138 ms 46024 KB Output is correct
42 Correct 209 ms 22404 KB Output is correct
43 Correct 248 ms 15992 KB Output is correct
44 Correct 670 ms 33780 KB Output is correct
45 Correct 942 ms 40792 KB Output is correct
46 Correct 1084 ms 47196 KB Output is correct
47 Correct 1048 ms 46328 KB Output is correct
48 Correct 507 ms 34448 KB Output is correct
49 Correct 382 ms 34296 KB Output is correct
50 Correct 469 ms 34296 KB Output is correct
51 Correct 421 ms 34300 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 1167 ms 45988 KB Output is correct
54 Correct 659 ms 33736 KB Output is correct
55 Correct 986 ms 40384 KB Output is correct
56 Correct 1044 ms 46840 KB Output is correct
57 Correct 2224 ms 157840 KB Output is correct
58 Correct 2292 ms 157712 KB Output is correct
59 Correct 2480 ms 157436 KB Output is correct
60 Correct 2288 ms 157176 KB Output is correct
61 Correct 8164 ms 217548 KB Output is correct
62 Correct 3906 ms 151004 KB Output is correct
63 Correct 5351 ms 173564 KB Output is correct
64 Correct 7241 ms 212716 KB Output is correct
65 Correct 426 ms 33500 KB Output is correct
66 Correct 463 ms 33452 KB Output is correct
67 Correct 429 ms 33548 KB Output is correct
68 Correct 444 ms 33560 KB Output is correct
69 Correct 1068 ms 46200 KB Output is correct
70 Correct 3 ms 512 KB Output is correct
71 Correct 1260 ms 45156 KB Output is correct
72 Correct 715 ms 32436 KB Output is correct
73 Correct 945 ms 39900 KB Output is correct
74 Correct 1024 ms 44712 KB Output is correct
75 Correct 2305 ms 157080 KB Output is correct
76 Correct 2409 ms 157144 KB Output is correct
77 Correct 2472 ms 156992 KB Output is correct
78 Correct 2211 ms 157348 KB Output is correct
79 Correct 7815 ms 217304 KB Output is correct
80 Correct 4059 ms 148624 KB Output is correct
81 Correct 5007 ms 178612 KB Output is correct
82 Correct 7685 ms 216136 KB Output is correct
83 Correct 6883 ms 208408 KB Output is correct