Submission #1070253

# Submission time Handle Problem Language Result Execution time Memory
1070253 2024-08-22T12:30:36 Z Ahmed57 Two Dishes (JOI19_dishes) C++17
74 / 100
2537 ms 215792 KB
#include "bits/stdc++.h"
 
using namespace std;
#define int long long
vector<pair<int,int>> lol[1000001];
int arr1[1000001] = {0};
int arr2[1000001] = {0};
int a[1000001];int s[1000001];int p[1000001];
int b[1000001];int t[1000001];int q[1000001];
signed main(){
	int n,m;
	cin>>n>>m;
	for(int i = 1;i<=n;i++){
		cin>>a[i]>>s[i]>>p[i];
		arr1[i] = a[i]+arr1[i-1];
	}
	for(int i = 1;i<=m;i++){
		cin>>b[i]>>t[i]>>q[i];
		arr2[i] = b[i]+arr2[i-1];
	}
	for(int i = 1;i<=n;i++){
		int l = 0 , r = m , ans = -1;
		while(l<=r){
			int mid = (l+r)/2;
			if(arr2[mid]+arr1[i]<=s[i]){
				ans = mid;l = mid+1;
			}else r = mid-1;
		}
		if(ans==-1)continue;
		lol[ans].push_back({i,p[i]});
	}
	long long all = 0;
	for(int i = 1;i<=m;i++){
		int l = 0 , r = n , ans = -1;
		while(l<=r){
			int mid = (l+r)/2;
			if(arr2[i]+arr1[mid]<=t[i]){
				ans = mid;l = mid+1;
			}else r = mid-1;
		}
		if(ans==-1)continue;
		if(ans!=n)lol[i-1].push_back({ans+1,-q[i]});
		all+=q[i];
	}
	map<int,int> mp;
	for(int i = 0;i<=m;i++){
		for(auto j:lol[i]){
			if(j.second>=0||i==n){
				mp[j.first]+=j.second;
                continue;
			}
			int ans = j.second;
			auto it = mp.lower_bound(j.first);
			while(it!=mp.end()){
				if(ans+(*it).second>=0){
					mp[(*it).first]+=ans;
					ans = 0;
					break;
				}
				ans+=(*it).second;
				it = mp.erase(it);
			}
		}
	}
	for(auto i:mp)all+=i.second;
	cout<<all<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 413 ms 66900 KB Output is correct
2 Correct 422 ms 77508 KB Output is correct
3 Correct 412 ms 60380 KB Output is correct
4 Correct 370 ms 54012 KB Output is correct
5 Correct 6 ms 35052 KB Output is correct
6 Correct 430 ms 56112 KB Output is correct
7 Correct 199 ms 47408 KB Output is correct
8 Correct 243 ms 61720 KB Output is correct
9 Correct 416 ms 74484 KB Output is correct
10 Correct 281 ms 63968 KB Output is correct
11 Correct 270 ms 70836 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 34908 KB Output is correct
2 Correct 5 ms 34908 KB Output is correct
3 Correct 6 ms 34908 KB Output is correct
4 Correct 5 ms 34904 KB Output is correct
5 Correct 5 ms 34908 KB Output is correct
6 Correct 7 ms 35032 KB Output is correct
7 Correct 6 ms 34908 KB Output is correct
8 Correct 5 ms 34908 KB Output is correct
9 Correct 5 ms 34908 KB Output is correct
10 Correct 5 ms 34908 KB Output is correct
11 Correct 5 ms 34908 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 5 ms 34908 KB Output is correct
15 Correct 5 ms 34852 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 34908 KB Output is correct
2 Correct 5 ms 34908 KB Output is correct
3 Correct 6 ms 34908 KB Output is correct
4 Correct 5 ms 34904 KB Output is correct
5 Correct 5 ms 34908 KB Output is correct
6 Correct 7 ms 35032 KB Output is correct
7 Correct 6 ms 34908 KB Output is correct
8 Correct 5 ms 34908 KB Output is correct
9 Correct 5 ms 34908 KB Output is correct
10 Correct 5 ms 34908 KB Output is correct
11 Correct 5 ms 34908 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 5 ms 34908 KB Output is correct
15 Correct 5 ms 34852 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 8 ms 35164 KB Output is correct
18 Correct 7 ms 35164 KB Output is correct
19 Correct 8 ms 35164 KB Output is correct
20 Correct 8 ms 35164 KB Output is correct
21 Correct 8 ms 35168 KB Output is correct
22 Correct 8 ms 35160 KB Output is correct
23 Correct 7 ms 35060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 34908 KB Output is correct
2 Correct 5 ms 34908 KB Output is correct
3 Correct 6 ms 34908 KB Output is correct
4 Correct 5 ms 34904 KB Output is correct
5 Correct 5 ms 34908 KB Output is correct
6 Correct 7 ms 35032 KB Output is correct
7 Correct 6 ms 34908 KB Output is correct
8 Correct 5 ms 34908 KB Output is correct
9 Correct 5 ms 34908 KB Output is correct
10 Correct 5 ms 34908 KB Output is correct
11 Correct 5 ms 34908 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 5 ms 34908 KB Output is correct
15 Correct 5 ms 34852 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 8 ms 35164 KB Output is correct
18 Correct 7 ms 35164 KB Output is correct
19 Correct 8 ms 35164 KB Output is correct
20 Correct 8 ms 35164 KB Output is correct
21 Correct 8 ms 35168 KB Output is correct
22 Correct 8 ms 35160 KB Output is correct
23 Correct 7 ms 35060 KB Output is correct
24 Correct 320 ms 72572 KB Output is correct
25 Correct 309 ms 70320 KB Output is correct
26 Correct 334 ms 75092 KB Output is correct
27 Correct 327 ms 70648 KB Output is correct
28 Correct 349 ms 69084 KB Output is correct
29 Correct 341 ms 72816 KB Output is correct
30 Correct 415 ms 66640 KB Output is correct
31 Correct 155 ms 49748 KB Output is correct
32 Correct 184 ms 60540 KB Output is correct
33 Correct 340 ms 61524 KB Output is correct
34 Correct 397 ms 73384 KB Output is correct
35 Correct 277 ms 63208 KB Output is correct
36 Correct 288 ms 63084 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 34908 KB Output is correct
2 Correct 5 ms 34908 KB Output is correct
3 Correct 6 ms 34908 KB Output is correct
4 Correct 5 ms 34904 KB Output is correct
5 Correct 5 ms 34908 KB Output is correct
6 Correct 7 ms 35032 KB Output is correct
7 Correct 6 ms 34908 KB Output is correct
8 Correct 5 ms 34908 KB Output is correct
9 Correct 5 ms 34908 KB Output is correct
10 Correct 5 ms 34908 KB Output is correct
11 Correct 5 ms 34908 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 5 ms 34908 KB Output is correct
15 Correct 5 ms 34852 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 8 ms 35164 KB Output is correct
18 Correct 7 ms 35164 KB Output is correct
19 Correct 8 ms 35164 KB Output is correct
20 Correct 8 ms 35164 KB Output is correct
21 Correct 8 ms 35168 KB Output is correct
22 Correct 8 ms 35160 KB Output is correct
23 Correct 7 ms 35060 KB Output is correct
24 Correct 320 ms 72572 KB Output is correct
25 Correct 309 ms 70320 KB Output is correct
26 Correct 334 ms 75092 KB Output is correct
27 Correct 327 ms 70648 KB Output is correct
28 Correct 349 ms 69084 KB Output is correct
29 Correct 341 ms 72816 KB Output is correct
30 Correct 415 ms 66640 KB Output is correct
31 Correct 155 ms 49748 KB Output is correct
32 Correct 184 ms 60540 KB Output is correct
33 Correct 340 ms 61524 KB Output is correct
34 Correct 397 ms 73384 KB Output is correct
35 Correct 277 ms 63208 KB Output is correct
36 Correct 288 ms 63084 KB Output is correct
37 Correct 404 ms 76516 KB Output is correct
38 Correct 370 ms 72124 KB Output is correct
39 Correct 312 ms 65620 KB Output is correct
40 Correct 385 ms 78416 KB Output is correct
41 Correct 6 ms 34908 KB Output is correct
42 Correct 471 ms 67960 KB Output is correct
43 Correct 391 ms 63056 KB Output is correct
44 Correct 450 ms 74740 KB Output is correct
45 Correct 345 ms 64740 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 34908 KB Output is correct
2 Correct 5 ms 34908 KB Output is correct
3 Correct 6 ms 34908 KB Output is correct
4 Correct 5 ms 34904 KB Output is correct
5 Correct 5 ms 34908 KB Output is correct
6 Correct 7 ms 35032 KB Output is correct
7 Correct 6 ms 34908 KB Output is correct
8 Correct 5 ms 34908 KB Output is correct
9 Correct 5 ms 34908 KB Output is correct
10 Correct 5 ms 34908 KB Output is correct
11 Correct 5 ms 34908 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 5 ms 34908 KB Output is correct
15 Correct 5 ms 34852 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 8 ms 35164 KB Output is correct
18 Correct 7 ms 35164 KB Output is correct
19 Correct 8 ms 35164 KB Output is correct
20 Correct 8 ms 35164 KB Output is correct
21 Correct 8 ms 35168 KB Output is correct
22 Correct 8 ms 35160 KB Output is correct
23 Correct 7 ms 35060 KB Output is correct
24 Correct 320 ms 72572 KB Output is correct
25 Correct 309 ms 70320 KB Output is correct
26 Correct 334 ms 75092 KB Output is correct
27 Correct 327 ms 70648 KB Output is correct
28 Correct 349 ms 69084 KB Output is correct
29 Correct 341 ms 72816 KB Output is correct
30 Correct 415 ms 66640 KB Output is correct
31 Correct 155 ms 49748 KB Output is correct
32 Correct 184 ms 60540 KB Output is correct
33 Correct 340 ms 61524 KB Output is correct
34 Correct 397 ms 73384 KB Output is correct
35 Correct 277 ms 63208 KB Output is correct
36 Correct 288 ms 63084 KB Output is correct
37 Correct 404 ms 76516 KB Output is correct
38 Correct 370 ms 72124 KB Output is correct
39 Correct 312 ms 65620 KB Output is correct
40 Correct 385 ms 78416 KB Output is correct
41 Correct 6 ms 34908 KB Output is correct
42 Correct 471 ms 67960 KB Output is correct
43 Correct 391 ms 63056 KB Output is correct
44 Correct 450 ms 74740 KB Output is correct
45 Correct 345 ms 64740 KB Output is correct
46 Correct 2000 ms 215792 KB Output is correct
47 Correct 1896 ms 192316 KB Output is correct
48 Correct 1631 ms 141392 KB Output is correct
49 Correct 2005 ms 196092 KB Output is correct
50 Correct 2537 ms 137424 KB Output is correct
51 Correct 2024 ms 112464 KB Output is correct
52 Correct 2292 ms 171180 KB Output is correct
53 Correct 1888 ms 137156 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 413 ms 66900 KB Output is correct
2 Correct 422 ms 77508 KB Output is correct
3 Correct 412 ms 60380 KB Output is correct
4 Correct 370 ms 54012 KB Output is correct
5 Correct 6 ms 35052 KB Output is correct
6 Correct 430 ms 56112 KB Output is correct
7 Correct 199 ms 47408 KB Output is correct
8 Correct 243 ms 61720 KB Output is correct
9 Correct 416 ms 74484 KB Output is correct
10 Correct 281 ms 63968 KB Output is correct
11 Correct 270 ms 70836 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 6 ms 34908 KB Output is correct
15 Correct 5 ms 34904 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 7 ms 35032 KB Output is correct
18 Correct 6 ms 34908 KB Output is correct
19 Correct 5 ms 34908 KB Output is correct
20 Correct 5 ms 34908 KB Output is correct
21 Correct 5 ms 34908 KB Output is correct
22 Correct 5 ms 34908 KB Output is correct
23 Correct 5 ms 34908 KB Output is correct
24 Correct 5 ms 34908 KB Output is correct
25 Correct 5 ms 34908 KB Output is correct
26 Correct 5 ms 34852 KB Output is correct
27 Correct 5 ms 34908 KB Output is correct
28 Correct 8 ms 35164 KB Output is correct
29 Correct 7 ms 35164 KB Output is correct
30 Correct 8 ms 35164 KB Output is correct
31 Correct 8 ms 35164 KB Output is correct
32 Correct 8 ms 35168 KB Output is correct
33 Correct 8 ms 35160 KB Output is correct
34 Correct 7 ms 35060 KB Output is correct
35 Correct 320 ms 72572 KB Output is correct
36 Correct 309 ms 70320 KB Output is correct
37 Correct 334 ms 75092 KB Output is correct
38 Correct 327 ms 70648 KB Output is correct
39 Correct 349 ms 69084 KB Output is correct
40 Correct 341 ms 72816 KB Output is correct
41 Correct 415 ms 66640 KB Output is correct
42 Correct 155 ms 49748 KB Output is correct
43 Correct 184 ms 60540 KB Output is correct
44 Correct 340 ms 61524 KB Output is correct
45 Correct 397 ms 73384 KB Output is correct
46 Correct 277 ms 63208 KB Output is correct
47 Correct 288 ms 63084 KB Output is correct
48 Correct 404 ms 76516 KB Output is correct
49 Correct 370 ms 72124 KB Output is correct
50 Correct 312 ms 65620 KB Output is correct
51 Correct 385 ms 78416 KB Output is correct
52 Correct 6 ms 34908 KB Output is correct
53 Correct 471 ms 67960 KB Output is correct
54 Correct 391 ms 63056 KB Output is correct
55 Correct 450 ms 74740 KB Output is correct
56 Correct 345 ms 64740 KB Output is correct
57 Correct 400 ms 56984 KB Output is correct
58 Correct 431 ms 71112 KB Output is correct
59 Incorrect 400 ms 72452 KB Output isn't correct
60 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 413 ms 66900 KB Output is correct
2 Correct 422 ms 77508 KB Output is correct
3 Correct 412 ms 60380 KB Output is correct
4 Correct 370 ms 54012 KB Output is correct
5 Correct 6 ms 35052 KB Output is correct
6 Correct 430 ms 56112 KB Output is correct
7 Correct 199 ms 47408 KB Output is correct
8 Correct 243 ms 61720 KB Output is correct
9 Correct 416 ms 74484 KB Output is correct
10 Correct 281 ms 63968 KB Output is correct
11 Correct 270 ms 70836 KB Output is correct
12 Correct 5 ms 34908 KB Output is correct
13 Correct 5 ms 34908 KB Output is correct
14 Correct 6 ms 34908 KB Output is correct
15 Correct 5 ms 34904 KB Output is correct
16 Correct 5 ms 34908 KB Output is correct
17 Correct 7 ms 35032 KB Output is correct
18 Correct 6 ms 34908 KB Output is correct
19 Correct 5 ms 34908 KB Output is correct
20 Correct 5 ms 34908 KB Output is correct
21 Correct 5 ms 34908 KB Output is correct
22 Correct 5 ms 34908 KB Output is correct
23 Correct 5 ms 34908 KB Output is correct
24 Correct 5 ms 34908 KB Output is correct
25 Correct 5 ms 34908 KB Output is correct
26 Correct 5 ms 34852 KB Output is correct
27 Correct 5 ms 34908 KB Output is correct
28 Correct 8 ms 35164 KB Output is correct
29 Correct 7 ms 35164 KB Output is correct
30 Correct 8 ms 35164 KB Output is correct
31 Correct 8 ms 35164 KB Output is correct
32 Correct 8 ms 35168 KB Output is correct
33 Correct 8 ms 35160 KB Output is correct
34 Correct 7 ms 35060 KB Output is correct
35 Correct 320 ms 72572 KB Output is correct
36 Correct 309 ms 70320 KB Output is correct
37 Correct 334 ms 75092 KB Output is correct
38 Correct 327 ms 70648 KB Output is correct
39 Correct 349 ms 69084 KB Output is correct
40 Correct 341 ms 72816 KB Output is correct
41 Correct 415 ms 66640 KB Output is correct
42 Correct 155 ms 49748 KB Output is correct
43 Correct 184 ms 60540 KB Output is correct
44 Correct 340 ms 61524 KB Output is correct
45 Correct 397 ms 73384 KB Output is correct
46 Correct 277 ms 63208 KB Output is correct
47 Correct 288 ms 63084 KB Output is correct
48 Correct 404 ms 76516 KB Output is correct
49 Correct 370 ms 72124 KB Output is correct
50 Correct 312 ms 65620 KB Output is correct
51 Correct 385 ms 78416 KB Output is correct
52 Correct 6 ms 34908 KB Output is correct
53 Correct 471 ms 67960 KB Output is correct
54 Correct 391 ms 63056 KB Output is correct
55 Correct 450 ms 74740 KB Output is correct
56 Correct 345 ms 64740 KB Output is correct
57 Correct 2000 ms 215792 KB Output is correct
58 Correct 1896 ms 192316 KB Output is correct
59 Correct 1631 ms 141392 KB Output is correct
60 Correct 2005 ms 196092 KB Output is correct
61 Correct 2537 ms 137424 KB Output is correct
62 Correct 2024 ms 112464 KB Output is correct
63 Correct 2292 ms 171180 KB Output is correct
64 Correct 1888 ms 137156 KB Output is correct
65 Correct 400 ms 56984 KB Output is correct
66 Correct 431 ms 71112 KB Output is correct
67 Incorrect 400 ms 72452 KB Output isn't correct
68 Halted 0 ms 0 KB -