Submission #260217

# Submission time Handle Problem Language Result Execution time Memory
260217 2020-08-09T19:15:51 Z patrikpavic2 Two Dishes (JOI19_dishes) C++17
100 / 100
3087 ms 171384 KB
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>
 
#define PB push_back
 
using namespace std;
 
typedef long long ll;
 
const int N = 1e6 + 500;
const ll INF = 1e18;
 
ll del[N], S[N], T[N];
int n, m;
int Q[N], P[N], A[N], B[N];
int SS[N], TT[N];
vector < ll > v, v2;
vector < int > brisi[N];
set < int > raz;

void pocisti(int sad){
	if(del[sad] > 0){
		raz.insert(sad);
		return;
	}
	if(!del[sad] && raz.count(sad))
		raz.erase(sad);
	if(del[sad] >= 0) return;
	ll trb = -del[sad];
	del[sad] = 0;
	sad++;
	while(sad <= m && trb > 0){
		if(del[sad] > trb){
			del[sad] -= trb;
			break;
		}
		trb -= del[sad]; del[sad] = 0;
		raz.erase(sad);
		if(raz.lower_bound(sad) == raz.end())
			break;
		sad = *(raz.upper_bound(sad));
	}
}

 
int main(){
	scanf("%d%d", &n, &m);
	for(int i = 1;i <= n;i++)
		scanf("%d%lld%d", A + i, S + i, P + i);
	for(int i = 1;i <= m;i++)
		scanf("%d%lld%d", B + i, T + i, Q + i);
	ll cur = 0; v.PB(cur);
	for(int i = 1;i <= m;i++)
		cur += B[i], v.PB(cur);
	cur = 0; v2.PB(cur);
	for(int i = 1;i <= n;i++){
		cur += A[i]; v2.PB(cur);
		if(S[i] < cur)
			P[i] = 0, S[i] = cur;
		SS[i] = upper_bound(v.begin(), v.end(), S[i] - cur) - v.begin() - 1;
	}
	cur = 0;
	for(int i = 1;i <= m;i++){
		cur += B[i];
		if(T[i] < cur)
			Q[i] = 0, T[i] = cur;
		TT[i] = upper_bound(v2.begin(), v2.end(), T[i] - cur) - v2.begin() - 1;
	}
	ll ans = 0;
	for(int i = 1;i <= m;i++){
		brisi[TT[i] + 1].PB(i);	
	}
	for(int i = 1;i <= n;i++){
		for(int bla = 0;bla < 2;bla++){
			if((P[i] > 0) ^ !bla){
				del[0] += P[i];
				del[SS[i] + 1] -= P[i];		
				pocisti(SS[i] + 1);
			}
			for(int j : brisi[i]){
				if((Q[j] < 0) ^ !bla){
					del[0] -= Q[j];
					del[j] += Q[j];
					ans += Q[j];
					pocisti(j);
				}
			}
		}
	}
	for(int j : brisi[n + 1])
		ans += Q[j];
	for(int i = 0;i <= m;i++)
		ans += del[i];
	printf("%lld\n", ans);
}

Compilation message

dishes.cpp: In function 'int main()':
dishes.cpp:50: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:52:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", A + i, S + i, P + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
dishes.cpp:54:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%lld%d", B + i, T + i, Q + i);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 318 ms 48740 KB Output is correct
2 Correct 297 ms 39776 KB Output is correct
3 Correct 232 ms 36584 KB Output is correct
4 Correct 313 ms 46048 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 269 ms 38676 KB Output is correct
7 Correct 147 ms 31336 KB Output is correct
8 Correct 119 ms 29676 KB Output is correct
9 Correct 234 ms 36612 KB Output is correct
10 Correct 234 ms 42848 KB Output is correct
11 Correct 170 ms 36712 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 16 ms 24064 KB Output is correct
18 Correct 19 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24064 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 16 ms 24064 KB Output is correct
18 Correct 19 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24064 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
24 Correct 221 ms 37604 KB Output is correct
25 Correct 283 ms 46688 KB Output is correct
26 Correct 231 ms 37864 KB Output is correct
27 Correct 300 ms 52044 KB Output is correct
28 Correct 321 ms 38500 KB Output is correct
29 Correct 204 ms 36712 KB Output is correct
30 Correct 448 ms 40428 KB Output is correct
31 Correct 136 ms 36580 KB Output is correct
32 Correct 112 ms 29676 KB Output is correct
33 Correct 341 ms 39136 KB Output is correct
34 Correct 398 ms 42680 KB Output is correct
35 Correct 382 ms 40456 KB Output is correct
36 Correct 364 ms 40416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 16 ms 24064 KB Output is correct
18 Correct 19 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24064 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
24 Correct 221 ms 37604 KB Output is correct
25 Correct 283 ms 46688 KB Output is correct
26 Correct 231 ms 37864 KB Output is correct
27 Correct 300 ms 52044 KB Output is correct
28 Correct 321 ms 38500 KB Output is correct
29 Correct 204 ms 36712 KB Output is correct
30 Correct 448 ms 40428 KB Output is correct
31 Correct 136 ms 36580 KB Output is correct
32 Correct 112 ms 29676 KB Output is correct
33 Correct 341 ms 39136 KB Output is correct
34 Correct 398 ms 42680 KB Output is correct
35 Correct 382 ms 40456 KB Output is correct
36 Correct 364 ms 40416 KB Output is correct
37 Correct 274 ms 37732 KB Output is correct
38 Correct 350 ms 52060 KB Output is correct
39 Correct 353 ms 52064 KB Output is correct
40 Correct 262 ms 42720 KB Output is correct
41 Correct 16 ms 23808 KB Output is correct
42 Correct 495 ms 40388 KB Output is correct
43 Correct 437 ms 39136 KB Output is correct
44 Correct 439 ms 42804 KB Output is correct
45 Correct 409 ms 40416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 23808 KB Output is correct
2 Correct 14 ms 23808 KB Output is correct
3 Correct 14 ms 23808 KB Output is correct
4 Correct 16 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 15 ms 23808 KB Output is correct
7 Correct 14 ms 23808 KB Output is correct
8 Correct 14 ms 23808 KB Output is correct
9 Correct 14 ms 23808 KB Output is correct
10 Correct 15 ms 23808 KB Output is correct
11 Correct 14 ms 23808 KB Output is correct
12 Correct 14 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 14 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 16 ms 24064 KB Output is correct
18 Correct 19 ms 24064 KB Output is correct
19 Correct 18 ms 24064 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24064 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24064 KB Output is correct
24 Correct 221 ms 37604 KB Output is correct
25 Correct 283 ms 46688 KB Output is correct
26 Correct 231 ms 37864 KB Output is correct
27 Correct 300 ms 52044 KB Output is correct
28 Correct 321 ms 38500 KB Output is correct
29 Correct 204 ms 36712 KB Output is correct
30 Correct 448 ms 40428 KB Output is correct
31 Correct 136 ms 36580 KB Output is correct
32 Correct 112 ms 29676 KB Output is correct
33 Correct 341 ms 39136 KB Output is correct
34 Correct 398 ms 42680 KB Output is correct
35 Correct 382 ms 40456 KB Output is correct
36 Correct 364 ms 40416 KB Output is correct
37 Correct 274 ms 37732 KB Output is correct
38 Correct 350 ms 52060 KB Output is correct
39 Correct 353 ms 52064 KB Output is correct
40 Correct 262 ms 42720 KB Output is correct
41 Correct 16 ms 23808 KB Output is correct
42 Correct 495 ms 40388 KB Output is correct
43 Correct 437 ms 39136 KB Output is correct
44 Correct 439 ms 42804 KB Output is correct
45 Correct 409 ms 40416 KB Output is correct
46 Correct 1315 ms 93276 KB Output is correct
47 Correct 1796 ms 164744 KB Output is correct
48 Correct 1826 ms 164672 KB Output is correct
49 Correct 1355 ms 117776 KB Output is correct
50 Correct 3087 ms 106336 KB Output is correct
51 Correct 2128 ms 98396 KB Output is correct
52 Correct 2520 ms 114996 KB Output is correct
53 Correct 2643 ms 106172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 48740 KB Output is correct
2 Correct 297 ms 39776 KB Output is correct
3 Correct 232 ms 36584 KB Output is correct
4 Correct 313 ms 46048 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 269 ms 38676 KB Output is correct
7 Correct 147 ms 31336 KB Output is correct
8 Correct 119 ms 29676 KB Output is correct
9 Correct 234 ms 36612 KB Output is correct
10 Correct 234 ms 42848 KB Output is correct
11 Correct 170 ms 36712 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 14 ms 23808 KB Output is correct
20 Correct 14 ms 23808 KB Output is correct
21 Correct 15 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 14 ms 23808 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 14 ms 23808 KB Output is correct
28 Correct 16 ms 24064 KB Output is correct
29 Correct 19 ms 24064 KB Output is correct
30 Correct 18 ms 24064 KB Output is correct
31 Correct 17 ms 24064 KB Output is correct
32 Correct 17 ms 24064 KB Output is correct
33 Correct 17 ms 24064 KB Output is correct
34 Correct 17 ms 24064 KB Output is correct
35 Correct 221 ms 37604 KB Output is correct
36 Correct 283 ms 46688 KB Output is correct
37 Correct 231 ms 37864 KB Output is correct
38 Correct 300 ms 52044 KB Output is correct
39 Correct 321 ms 38500 KB Output is correct
40 Correct 204 ms 36712 KB Output is correct
41 Correct 448 ms 40428 KB Output is correct
42 Correct 136 ms 36580 KB Output is correct
43 Correct 112 ms 29676 KB Output is correct
44 Correct 341 ms 39136 KB Output is correct
45 Correct 398 ms 42680 KB Output is correct
46 Correct 382 ms 40456 KB Output is correct
47 Correct 364 ms 40416 KB Output is correct
48 Correct 274 ms 37732 KB Output is correct
49 Correct 350 ms 52060 KB Output is correct
50 Correct 353 ms 52064 KB Output is correct
51 Correct 262 ms 42720 KB Output is correct
52 Correct 16 ms 23808 KB Output is correct
53 Correct 495 ms 40388 KB Output is correct
54 Correct 437 ms 39136 KB Output is correct
55 Correct 439 ms 42804 KB Output is correct
56 Correct 409 ms 40416 KB Output is correct
57 Correct 328 ms 46564 KB Output is correct
58 Correct 291 ms 50644 KB Output is correct
59 Correct 263 ms 52576 KB Output is correct
60 Correct 354 ms 61792 KB Output is correct
61 Correct 354 ms 51296 KB Output is correct
62 Correct 14 ms 23808 KB Output is correct
63 Correct 504 ms 48640 KB Output is correct
64 Correct 395 ms 47332 KB Output is correct
65 Correct 437 ms 48028 KB Output is correct
66 Correct 423 ms 47968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 318 ms 48740 KB Output is correct
2 Correct 297 ms 39776 KB Output is correct
3 Correct 232 ms 36584 KB Output is correct
4 Correct 313 ms 46048 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 269 ms 38676 KB Output is correct
7 Correct 147 ms 31336 KB Output is correct
8 Correct 119 ms 29676 KB Output is correct
9 Correct 234 ms 36612 KB Output is correct
10 Correct 234 ms 42848 KB Output is correct
11 Correct 170 ms 36712 KB Output is correct
12 Correct 16 ms 23808 KB Output is correct
13 Correct 14 ms 23808 KB Output is correct
14 Correct 14 ms 23808 KB Output is correct
15 Correct 16 ms 23808 KB Output is correct
16 Correct 14 ms 23808 KB Output is correct
17 Correct 15 ms 23808 KB Output is correct
18 Correct 14 ms 23808 KB Output is correct
19 Correct 14 ms 23808 KB Output is correct
20 Correct 14 ms 23808 KB Output is correct
21 Correct 15 ms 23808 KB Output is correct
22 Correct 14 ms 23808 KB Output is correct
23 Correct 14 ms 23808 KB Output is correct
24 Correct 14 ms 23808 KB Output is correct
25 Correct 14 ms 23808 KB Output is correct
26 Correct 14 ms 23808 KB Output is correct
27 Correct 14 ms 23808 KB Output is correct
28 Correct 16 ms 24064 KB Output is correct
29 Correct 19 ms 24064 KB Output is correct
30 Correct 18 ms 24064 KB Output is correct
31 Correct 17 ms 24064 KB Output is correct
32 Correct 17 ms 24064 KB Output is correct
33 Correct 17 ms 24064 KB Output is correct
34 Correct 17 ms 24064 KB Output is correct
35 Correct 221 ms 37604 KB Output is correct
36 Correct 283 ms 46688 KB Output is correct
37 Correct 231 ms 37864 KB Output is correct
38 Correct 300 ms 52044 KB Output is correct
39 Correct 321 ms 38500 KB Output is correct
40 Correct 204 ms 36712 KB Output is correct
41 Correct 448 ms 40428 KB Output is correct
42 Correct 136 ms 36580 KB Output is correct
43 Correct 112 ms 29676 KB Output is correct
44 Correct 341 ms 39136 KB Output is correct
45 Correct 398 ms 42680 KB Output is correct
46 Correct 382 ms 40456 KB Output is correct
47 Correct 364 ms 40416 KB Output is correct
48 Correct 274 ms 37732 KB Output is correct
49 Correct 350 ms 52060 KB Output is correct
50 Correct 353 ms 52064 KB Output is correct
51 Correct 262 ms 42720 KB Output is correct
52 Correct 16 ms 23808 KB Output is correct
53 Correct 495 ms 40388 KB Output is correct
54 Correct 437 ms 39136 KB Output is correct
55 Correct 439 ms 42804 KB Output is correct
56 Correct 409 ms 40416 KB Output is correct
57 Correct 1315 ms 93276 KB Output is correct
58 Correct 1796 ms 164744 KB Output is correct
59 Correct 1826 ms 164672 KB Output is correct
60 Correct 1355 ms 117776 KB Output is correct
61 Correct 3087 ms 106336 KB Output is correct
62 Correct 2128 ms 98396 KB Output is correct
63 Correct 2520 ms 114996 KB Output is correct
64 Correct 2643 ms 106172 KB Output is correct
65 Correct 328 ms 46564 KB Output is correct
66 Correct 291 ms 50644 KB Output is correct
67 Correct 263 ms 52576 KB Output is correct
68 Correct 354 ms 61792 KB Output is correct
69 Correct 354 ms 51296 KB Output is correct
70 Correct 14 ms 23808 KB Output is correct
71 Correct 504 ms 48640 KB Output is correct
72 Correct 395 ms 47332 KB Output is correct
73 Correct 437 ms 48028 KB Output is correct
74 Correct 423 ms 47968 KB Output is correct
75 Correct 1707 ms 145716 KB Output is correct
76 Correct 1422 ms 126020 KB Output is correct
77 Correct 1227 ms 124736 KB Output is correct
78 Correct 1868 ms 171384 KB Output is correct
79 Correct 2962 ms 113956 KB Output is correct
80 Correct 2120 ms 104936 KB Output is correct
81 Correct 2345 ms 107328 KB Output is correct
82 Correct 2598 ms 110608 KB Output is correct
83 Correct 2858 ms 111904 KB Output is correct