Submission #260215

# Submission time Handle Problem Language Result Execution time Memory
260215 2020-08-09T19:04:00 Z patrikpavic2 Two Dishes (JOI19_dishes) C++17
74 / 100
3059 ms 168444 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]].PB(i);	
	}
	for(int i = 0;i <= n;i++){
		if(i){
			del[0] += P[i]; //printf("del[0] += %d\n", P[i]);
			del[SS[i] + 1] -= P[i];		
			pocisti(SS[i] + 1);
		}
		//printf("od %d do %d + %d na %d\n", 0, SS[i], P[i], i);
		for(int j : brisi[i]){
			del[0] -= Q[j]; //printf("del[0] -= %d\n", Q[j]);
			del[j] += Q[j];
			ans += Q[j];
			//printf("od %d do %d + %d na %d\n", 0, j - 1, -Q[j], i);
			pocisti(j);
		}
		//printf("start = %lld\n", ans);
		//ll cur = ans;
		//for(int j = 0;j <= m;j++){
		//	cur += del[j];
		//	printf("%lld ", cur);
		//	if(j == m) printf("\n");
		//}
	}
	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 305 ms 59872 KB Output is correct
2 Correct 275 ms 52448 KB Output is correct
3 Correct 281 ms 57824 KB Output is correct
4 Correct 298 ms 57188 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 279 ms 52520 KB Output is correct
7 Correct 163 ms 45924 KB Output is correct
8 Correct 122 ms 35308 KB Output is correct
9 Correct 288 ms 56036 KB Output is correct
10 Correct 224 ms 48352 KB Output is correct
11 Correct 215 ms 52192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 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 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 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 14 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 14 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 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 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 14 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 17 ms 24192 KB Output is correct
18 Correct 16 ms 24192 KB Output is correct
19 Correct 17 ms 24192 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24192 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 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 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 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 14 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 17 ms 24192 KB Output is correct
18 Correct 16 ms 24192 KB Output is correct
19 Correct 17 ms 24192 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24192 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24060 KB Output is correct
24 Correct 245 ms 44384 KB Output is correct
25 Correct 280 ms 49368 KB Output is correct
26 Correct 265 ms 45024 KB Output is correct
27 Correct 296 ms 56164 KB Output is correct
28 Correct 317 ms 48736 KB Output is correct
29 Correct 264 ms 52576 KB Output is correct
30 Correct 480 ms 44640 KB Output is correct
31 Correct 161 ms 45544 KB Output is correct
32 Correct 117 ms 34028 KB Output is correct
33 Correct 340 ms 42976 KB Output is correct
34 Correct 393 ms 48096 KB Output is correct
35 Correct 373 ms 45000 KB Output is correct
36 Correct 371 ms 45048 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 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 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 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 14 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 17 ms 24192 KB Output is correct
18 Correct 16 ms 24192 KB Output is correct
19 Correct 17 ms 24192 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24192 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24060 KB Output is correct
24 Correct 245 ms 44384 KB Output is correct
25 Correct 280 ms 49368 KB Output is correct
26 Correct 265 ms 45024 KB Output is correct
27 Correct 296 ms 56164 KB Output is correct
28 Correct 317 ms 48736 KB Output is correct
29 Correct 264 ms 52576 KB Output is correct
30 Correct 480 ms 44640 KB Output is correct
31 Correct 161 ms 45544 KB Output is correct
32 Correct 117 ms 34028 KB Output is correct
33 Correct 340 ms 42976 KB Output is correct
34 Correct 393 ms 48096 KB Output is correct
35 Correct 373 ms 45000 KB Output is correct
36 Correct 371 ms 45048 KB Output is correct
37 Correct 298 ms 50912 KB Output is correct
38 Correct 345 ms 61028 KB Output is correct
39 Correct 351 ms 57920 KB Output is correct
40 Correct 262 ms 49248 KB Output is correct
41 Correct 14 ms 23808 KB Output is correct
42 Correct 515 ms 49556 KB Output is correct
43 Correct 383 ms 48240 KB Output is correct
44 Correct 434 ms 53256 KB Output is correct
45 Correct 403 ms 44896 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 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 14 ms 23808 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 14 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 14 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 17 ms 24192 KB Output is correct
18 Correct 16 ms 24192 KB Output is correct
19 Correct 17 ms 24192 KB Output is correct
20 Correct 17 ms 24064 KB Output is correct
21 Correct 17 ms 24192 KB Output is correct
22 Correct 17 ms 24064 KB Output is correct
23 Correct 17 ms 24060 KB Output is correct
24 Correct 245 ms 44384 KB Output is correct
25 Correct 280 ms 49368 KB Output is correct
26 Correct 265 ms 45024 KB Output is correct
27 Correct 296 ms 56164 KB Output is correct
28 Correct 317 ms 48736 KB Output is correct
29 Correct 264 ms 52576 KB Output is correct
30 Correct 480 ms 44640 KB Output is correct
31 Correct 161 ms 45544 KB Output is correct
32 Correct 117 ms 34028 KB Output is correct
33 Correct 340 ms 42976 KB Output is correct
34 Correct 393 ms 48096 KB Output is correct
35 Correct 373 ms 45000 KB Output is correct
36 Correct 371 ms 45048 KB Output is correct
37 Correct 298 ms 50912 KB Output is correct
38 Correct 345 ms 61028 KB Output is correct
39 Correct 351 ms 57920 KB Output is correct
40 Correct 262 ms 49248 KB Output is correct
41 Correct 14 ms 23808 KB Output is correct
42 Correct 515 ms 49556 KB Output is correct
43 Correct 383 ms 48240 KB Output is correct
44 Correct 434 ms 53256 KB Output is correct
45 Correct 403 ms 44896 KB Output is correct
46 Correct 1494 ms 119796 KB Output is correct
47 Correct 1781 ms 168444 KB Output is correct
48 Correct 1818 ms 167872 KB Output is correct
49 Correct 1228 ms 121280 KB Output is correct
50 Correct 3059 ms 109832 KB Output is correct
51 Correct 2131 ms 103188 KB Output is correct
52 Correct 2577 ms 124780 KB Output is correct
53 Correct 2584 ms 110768 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 305 ms 59872 KB Output is correct
2 Correct 275 ms 52448 KB Output is correct
3 Correct 281 ms 57824 KB Output is correct
4 Correct 298 ms 57188 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 279 ms 52520 KB Output is correct
7 Correct 163 ms 45924 KB Output is correct
8 Correct 122 ms 35308 KB Output is correct
9 Correct 288 ms 56036 KB Output is correct
10 Correct 224 ms 48352 KB Output is correct
11 Correct 215 ms 52192 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 14 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 14 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 17 ms 24192 KB Output is correct
29 Correct 16 ms 24192 KB Output is correct
30 Correct 17 ms 24192 KB Output is correct
31 Correct 17 ms 24064 KB Output is correct
32 Correct 17 ms 24192 KB Output is correct
33 Correct 17 ms 24064 KB Output is correct
34 Correct 17 ms 24060 KB Output is correct
35 Correct 245 ms 44384 KB Output is correct
36 Correct 280 ms 49368 KB Output is correct
37 Correct 265 ms 45024 KB Output is correct
38 Correct 296 ms 56164 KB Output is correct
39 Correct 317 ms 48736 KB Output is correct
40 Correct 264 ms 52576 KB Output is correct
41 Correct 480 ms 44640 KB Output is correct
42 Correct 161 ms 45544 KB Output is correct
43 Correct 117 ms 34028 KB Output is correct
44 Correct 340 ms 42976 KB Output is correct
45 Correct 393 ms 48096 KB Output is correct
46 Correct 373 ms 45000 KB Output is correct
47 Correct 371 ms 45048 KB Output is correct
48 Correct 298 ms 50912 KB Output is correct
49 Correct 345 ms 61028 KB Output is correct
50 Correct 351 ms 57920 KB Output is correct
51 Correct 262 ms 49248 KB Output is correct
52 Correct 14 ms 23808 KB Output is correct
53 Correct 515 ms 49556 KB Output is correct
54 Correct 383 ms 48240 KB Output is correct
55 Correct 434 ms 53256 KB Output is correct
56 Correct 403 ms 44896 KB Output is correct
57 Incorrect 349 ms 51424 KB Output isn't correct
58 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 305 ms 59872 KB Output is correct
2 Correct 275 ms 52448 KB Output is correct
3 Correct 281 ms 57824 KB Output is correct
4 Correct 298 ms 57188 KB Output is correct
5 Correct 14 ms 23808 KB Output is correct
6 Correct 279 ms 52520 KB Output is correct
7 Correct 163 ms 45924 KB Output is correct
8 Correct 122 ms 35308 KB Output is correct
9 Correct 288 ms 56036 KB Output is correct
10 Correct 224 ms 48352 KB Output is correct
11 Correct 215 ms 52192 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 14 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 14 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 17 ms 24192 KB Output is correct
29 Correct 16 ms 24192 KB Output is correct
30 Correct 17 ms 24192 KB Output is correct
31 Correct 17 ms 24064 KB Output is correct
32 Correct 17 ms 24192 KB Output is correct
33 Correct 17 ms 24064 KB Output is correct
34 Correct 17 ms 24060 KB Output is correct
35 Correct 245 ms 44384 KB Output is correct
36 Correct 280 ms 49368 KB Output is correct
37 Correct 265 ms 45024 KB Output is correct
38 Correct 296 ms 56164 KB Output is correct
39 Correct 317 ms 48736 KB Output is correct
40 Correct 264 ms 52576 KB Output is correct
41 Correct 480 ms 44640 KB Output is correct
42 Correct 161 ms 45544 KB Output is correct
43 Correct 117 ms 34028 KB Output is correct
44 Correct 340 ms 42976 KB Output is correct
45 Correct 393 ms 48096 KB Output is correct
46 Correct 373 ms 45000 KB Output is correct
47 Correct 371 ms 45048 KB Output is correct
48 Correct 298 ms 50912 KB Output is correct
49 Correct 345 ms 61028 KB Output is correct
50 Correct 351 ms 57920 KB Output is correct
51 Correct 262 ms 49248 KB Output is correct
52 Correct 14 ms 23808 KB Output is correct
53 Correct 515 ms 49556 KB Output is correct
54 Correct 383 ms 48240 KB Output is correct
55 Correct 434 ms 53256 KB Output is correct
56 Correct 403 ms 44896 KB Output is correct
57 Correct 1494 ms 119796 KB Output is correct
58 Correct 1781 ms 168444 KB Output is correct
59 Correct 1818 ms 167872 KB Output is correct
60 Correct 1228 ms 121280 KB Output is correct
61 Correct 3059 ms 109832 KB Output is correct
62 Correct 2131 ms 103188 KB Output is correct
63 Correct 2577 ms 124780 KB Output is correct
64 Correct 2584 ms 110768 KB Output is correct
65 Incorrect 349 ms 51424 KB Output isn't correct
66 Halted 0 ms 0 KB -