답안 #102081

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
102081 2019-03-22T07:10:10 Z ainta Two Dishes (JOI19_dishes) C++17
100 / 100
7990 ms 288000 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, DEBUG = 0;
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 D[110][110];
int main() {
	srand(1879);
	int i, j;
	scanf("%d%d", &n, &m);
	for (i = 1; i <= n; i++) {
		if (!DEBUG) {
			scanf("%d%lld%lld", &A[i].a, &A[i].t, &A[i].c);
		}
		else {
			A[i].a = rand() % 100;
			A[i].t = rand() % 300;
			A[i].c = rand() % 100 - 50;
		}
		SA[i] = SA[i - 1] + A[i].a;
	}
	for (i = 1; i <= m; i++) {
		if (!DEBUG) {
			scanf("%d%lld%lld", &B[i].a, &B[i].t, &B[i].c);
		}
		else {
			B[i].a = rand() % 100;
			B[i].t = rand() % 300;
			B[i].c = rand() % 100 - 50;
		}
		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);
	if (DEBUG) {
		for (i = 0; i <= n; i++)for (j = 0; j <= m; j++)D[i][j] = -1e9;
		D[0][0] = 0;
		for (i = 0; i <= n; i++) {
			for (j = 0; j <= m; j++) {
				if (i != n) {
					int t = D[i][j];
					if (SA[i + 1] + SB[j] <= A[i + 1].t)t += A[i + 1].c;
					D[i + 1][j] = max(D[i + 1][j], t);
				}
				if (j != m) {
					int t = D[i][j];
					if (SB[j + 1] + SA[i] <= B[j + 1].t)t += B[j + 1].c;
					D[i][j + 1] = max(D[i][j + 1], t);
				}
			}
		}
		printf("%d\n", D[n][m]);
	}
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:115:7: warning: unused variable 'x' [-Wunused-variable]
   int x = tp.first.first, y = -tp.first.second, c  = tp.second;
       ^
dishes.cpp:68: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:71:9: 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:82:9: 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);
    ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 33784 KB Output is correct
2 Correct 501 ms 32764 KB Output is correct
3 Correct 188 ms 12920 KB Output is correct
4 Correct 382 ms 24696 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 436 ms 28876 KB Output is correct
7 Correct 95 ms 6776 KB Output is correct
8 Correct 153 ms 6620 KB Output is correct
9 Correct 257 ms 12920 KB Output is correct
10 Correct 395 ms 31992 KB Output is correct
11 Correct 228 ms 13048 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 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 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 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 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 8 ms 868 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 896 KB Output is correct
23 Correct 7 ms 1024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 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 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 8 ms 868 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 896 KB Output is correct
23 Correct 7 ms 1024 KB Output is correct
24 Correct 520 ms 25792 KB Output is correct
25 Correct 467 ms 31776 KB Output is correct
26 Correct 374 ms 31876 KB Output is correct
27 Correct 405 ms 31840 KB Output is correct
28 Correct 530 ms 25728 KB Output is correct
29 Correct 196 ms 12960 KB Output is correct
30 Correct 1203 ms 43384 KB Output is correct
31 Correct 189 ms 19328 KB Output is correct
32 Correct 214 ms 13020 KB Output is correct
33 Correct 594 ms 31320 KB Output is correct
34 Correct 883 ms 38300 KB Output is correct
35 Correct 1024 ms 44104 KB Output is correct
36 Correct 1035 ms 43040 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 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 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 8 ms 868 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 896 KB Output is correct
23 Correct 7 ms 1024 KB Output is correct
24 Correct 520 ms 25792 KB Output is correct
25 Correct 467 ms 31776 KB Output is correct
26 Correct 374 ms 31876 KB Output is correct
27 Correct 405 ms 31840 KB Output is correct
28 Correct 530 ms 25728 KB Output is correct
29 Correct 196 ms 12960 KB Output is correct
30 Correct 1203 ms 43384 KB Output is correct
31 Correct 189 ms 19328 KB Output is correct
32 Correct 214 ms 13020 KB Output is correct
33 Correct 594 ms 31320 KB Output is correct
34 Correct 883 ms 38300 KB Output is correct
35 Correct 1024 ms 44104 KB Output is correct
36 Correct 1035 ms 43040 KB Output is correct
37 Correct 440 ms 31864 KB Output is correct
38 Correct 508 ms 31992 KB Output is correct
39 Correct 409 ms 31800 KB Output is correct
40 Correct 401 ms 31812 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 1211 ms 43472 KB Output is correct
43 Correct 611 ms 31212 KB Output is correct
44 Correct 971 ms 37840 KB Output is correct
45 Correct 1049 ms 43888 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 512 KB Output is correct
2 Correct 2 ms 384 KB Output is correct
3 Correct 3 ms 384 KB Output is correct
4 Correct 2 ms 512 KB Output is correct
5 Correct 2 ms 512 KB Output is correct
6 Correct 2 ms 512 KB Output is correct
7 Correct 2 ms 512 KB Output is correct
8 Correct 3 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 3 ms 512 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 8 ms 768 KB Output is correct
18 Correct 6 ms 768 KB Output is correct
19 Correct 8 ms 868 KB Output is correct
20 Correct 6 ms 768 KB Output is correct
21 Correct 9 ms 896 KB Output is correct
22 Correct 8 ms 896 KB Output is correct
23 Correct 7 ms 1024 KB Output is correct
24 Correct 520 ms 25792 KB Output is correct
25 Correct 467 ms 31776 KB Output is correct
26 Correct 374 ms 31876 KB Output is correct
27 Correct 405 ms 31840 KB Output is correct
28 Correct 530 ms 25728 KB Output is correct
29 Correct 196 ms 12960 KB Output is correct
30 Correct 1203 ms 43384 KB Output is correct
31 Correct 189 ms 19328 KB Output is correct
32 Correct 214 ms 13020 KB Output is correct
33 Correct 594 ms 31320 KB Output is correct
34 Correct 883 ms 38300 KB Output is correct
35 Correct 1024 ms 44104 KB Output is correct
36 Correct 1035 ms 43040 KB Output is correct
37 Correct 440 ms 31864 KB Output is correct
38 Correct 508 ms 31992 KB Output is correct
39 Correct 409 ms 31800 KB Output is correct
40 Correct 401 ms 31812 KB Output is correct
41 Correct 2 ms 512 KB Output is correct
42 Correct 1211 ms 43472 KB Output is correct
43 Correct 611 ms 31212 KB Output is correct
44 Correct 971 ms 37840 KB Output is correct
45 Correct 1049 ms 43888 KB Output is correct
46 Correct 2222 ms 157024 KB Output is correct
47 Correct 2277 ms 157036 KB Output is correct
48 Correct 2318 ms 157124 KB Output is correct
49 Correct 2555 ms 157116 KB Output is correct
50 Correct 7850 ms 217200 KB Output is correct
51 Correct 4285 ms 217732 KB Output is correct
52 Correct 5205 ms 239448 KB Output is correct
53 Correct 7990 ms 251280 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 33784 KB Output is correct
2 Correct 501 ms 32764 KB Output is correct
3 Correct 188 ms 12920 KB Output is correct
4 Correct 382 ms 24696 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 436 ms 28876 KB Output is correct
7 Correct 95 ms 6776 KB Output is correct
8 Correct 153 ms 6620 KB Output is correct
9 Correct 257 ms 12920 KB Output is correct
10 Correct 395 ms 31992 KB Output is correct
11 Correct 228 ms 13048 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 3 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 3 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 8 ms 868 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 8 ms 896 KB Output is correct
34 Correct 7 ms 1024 KB Output is correct
35 Correct 520 ms 25792 KB Output is correct
36 Correct 467 ms 31776 KB Output is correct
37 Correct 374 ms 31876 KB Output is correct
38 Correct 405 ms 31840 KB Output is correct
39 Correct 530 ms 25728 KB Output is correct
40 Correct 196 ms 12960 KB Output is correct
41 Correct 1203 ms 43384 KB Output is correct
42 Correct 189 ms 19328 KB Output is correct
43 Correct 214 ms 13020 KB Output is correct
44 Correct 594 ms 31320 KB Output is correct
45 Correct 883 ms 38300 KB Output is correct
46 Correct 1024 ms 44104 KB Output is correct
47 Correct 1035 ms 43040 KB Output is correct
48 Correct 440 ms 31864 KB Output is correct
49 Correct 508 ms 31992 KB Output is correct
50 Correct 409 ms 31800 KB Output is correct
51 Correct 401 ms 31812 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 1211 ms 43472 KB Output is correct
54 Correct 611 ms 31212 KB Output is correct
55 Correct 971 ms 37840 KB Output is correct
56 Correct 1049 ms 43888 KB Output is correct
57 Correct 394 ms 32616 KB Output is correct
58 Correct 439 ms 32476 KB Output is correct
59 Correct 433 ms 32568 KB Output is correct
60 Correct 458 ms 32508 KB Output is correct
61 Correct 1149 ms 45056 KB Output is correct
62 Correct 2 ms 512 KB Output is correct
63 Correct 1085 ms 44252 KB Output is correct
64 Correct 648 ms 31560 KB Output is correct
65 Correct 878 ms 39048 KB Output is correct
66 Correct 1281 ms 43872 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 532 ms 33784 KB Output is correct
2 Correct 501 ms 32764 KB Output is correct
3 Correct 188 ms 12920 KB Output is correct
4 Correct 382 ms 24696 KB Output is correct
5 Correct 3 ms 512 KB Output is correct
6 Correct 436 ms 28876 KB Output is correct
7 Correct 95 ms 6776 KB Output is correct
8 Correct 153 ms 6620 KB Output is correct
9 Correct 257 ms 12920 KB Output is correct
10 Correct 395 ms 31992 KB Output is correct
11 Correct 228 ms 13048 KB Output is correct
12 Correct 3 ms 512 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 3 ms 384 KB Output is correct
15 Correct 2 ms 512 KB Output is correct
16 Correct 2 ms 512 KB Output is correct
17 Correct 2 ms 512 KB Output is correct
18 Correct 2 ms 512 KB Output is correct
19 Correct 3 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 3 ms 512 KB Output is correct
26 Correct 2 ms 512 KB Output is correct
27 Correct 2 ms 512 KB Output is correct
28 Correct 8 ms 768 KB Output is correct
29 Correct 6 ms 768 KB Output is correct
30 Correct 8 ms 868 KB Output is correct
31 Correct 6 ms 768 KB Output is correct
32 Correct 9 ms 896 KB Output is correct
33 Correct 8 ms 896 KB Output is correct
34 Correct 7 ms 1024 KB Output is correct
35 Correct 520 ms 25792 KB Output is correct
36 Correct 467 ms 31776 KB Output is correct
37 Correct 374 ms 31876 KB Output is correct
38 Correct 405 ms 31840 KB Output is correct
39 Correct 530 ms 25728 KB Output is correct
40 Correct 196 ms 12960 KB Output is correct
41 Correct 1203 ms 43384 KB Output is correct
42 Correct 189 ms 19328 KB Output is correct
43 Correct 214 ms 13020 KB Output is correct
44 Correct 594 ms 31320 KB Output is correct
45 Correct 883 ms 38300 KB Output is correct
46 Correct 1024 ms 44104 KB Output is correct
47 Correct 1035 ms 43040 KB Output is correct
48 Correct 440 ms 31864 KB Output is correct
49 Correct 508 ms 31992 KB Output is correct
50 Correct 409 ms 31800 KB Output is correct
51 Correct 401 ms 31812 KB Output is correct
52 Correct 2 ms 512 KB Output is correct
53 Correct 1211 ms 43472 KB Output is correct
54 Correct 611 ms 31212 KB Output is correct
55 Correct 971 ms 37840 KB Output is correct
56 Correct 1049 ms 43888 KB Output is correct
57 Correct 2222 ms 157024 KB Output is correct
58 Correct 2277 ms 157036 KB Output is correct
59 Correct 2318 ms 157124 KB Output is correct
60 Correct 2555 ms 157116 KB Output is correct
61 Correct 7850 ms 217200 KB Output is correct
62 Correct 4285 ms 217732 KB Output is correct
63 Correct 5205 ms 239448 KB Output is correct
64 Correct 7990 ms 251280 KB Output is correct
65 Correct 394 ms 32616 KB Output is correct
66 Correct 439 ms 32476 KB Output is correct
67 Correct 433 ms 32568 KB Output is correct
68 Correct 458 ms 32508 KB Output is correct
69 Correct 1149 ms 45056 KB Output is correct
70 Correct 2 ms 512 KB Output is correct
71 Correct 1085 ms 44252 KB Output is correct
72 Correct 648 ms 31560 KB Output is correct
73 Correct 878 ms 39048 KB Output is correct
74 Correct 1281 ms 43872 KB Output is correct
75 Correct 2740 ms 228852 KB Output is correct
76 Correct 2719 ms 228904 KB Output is correct
77 Correct 2596 ms 215820 KB Output is correct
78 Correct 2671 ms 215892 KB Output is correct
79 Correct 7580 ms 288000 KB Output is correct
80 Correct 4295 ms 216328 KB Output is correct
81 Correct 5923 ms 245776 KB Output is correct
82 Correct 7766 ms 254364 KB Output is correct
83 Correct 7541 ms 267316 KB Output is correct