Submission #750670

# Submission time Handle Problem Language Result Execution time Memory
750670 2023-05-30T05:58:57 Z findingFish Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
141 ms 19140 KB
#include "bits/stdc++.h"
using namespace std;
 
const int N = 5e5 + 5;
long long a[N], b[N];
 
signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	long long res = 0;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
		a[i] -= b[i];
		a[i] += a[i-1];
	}
	
	long long mx = a[n]; assert(0 <= mx);
	for(int i=1;i<=n;i++){
		if(a[i] < 0){
			res -= a[i];
			a[i] = 0;
		}
		if(a[i] > mx){
			res += (a[i] - mx);
			a[i] = mx;
		}
	}
	
	priority_queue<long long> q;
	for(int i=1;i<=n;i++){
		q.push(a[i]);
		if(a[i] < q.top()){
			res += (q.top() - a[i]);
			q.pop(); q.push(a[i]);
		}
	}
	
	cout<<res<<"\n";
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 1752 KB Output is correct
5 Correct 14 ms 3672 KB Output is correct
6 Correct 42 ms 9760 KB Output is correct
7 Correct 88 ms 19104 KB Output is correct
8 Correct 77 ms 17172 KB Output is correct
9 Correct 70 ms 16544 KB Output is correct
10 Correct 50 ms 14260 KB Output is correct
11 Correct 52 ms 14296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 8 ms 1752 KB Output is correct
5 Correct 14 ms 3672 KB Output is correct
6 Correct 42 ms 9760 KB Output is correct
7 Correct 88 ms 19104 KB Output is correct
8 Correct 77 ms 17172 KB Output is correct
9 Correct 70 ms 16544 KB Output is correct
10 Correct 50 ms 14260 KB Output is correct
11 Correct 52 ms 14296 KB Output is correct
12 Correct 22 ms 5056 KB Output is correct
13 Correct 63 ms 13292 KB Output is correct
14 Correct 88 ms 19140 KB Output is correct
15 Correct 70 ms 17180 KB Output is correct
16 Correct 72 ms 16596 KB Output is correct
17 Correct 69 ms 14348 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 1 ms 340 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 468 KB Output is correct
17 Correct 1 ms 464 KB Output is correct
18 Correct 2 ms 392 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 8 ms 1752 KB Output is correct
12 Correct 14 ms 3672 KB Output is correct
13 Correct 42 ms 9760 KB Output is correct
14 Correct 88 ms 19104 KB Output is correct
15 Correct 77 ms 17172 KB Output is correct
16 Correct 70 ms 16544 KB Output is correct
17 Correct 50 ms 14260 KB Output is correct
18 Correct 52 ms 14296 KB Output is correct
19 Correct 22 ms 5056 KB Output is correct
20 Correct 63 ms 13292 KB Output is correct
21 Correct 88 ms 19140 KB Output is correct
22 Correct 70 ms 17180 KB Output is correct
23 Correct 72 ms 16596 KB Output is correct
24 Correct 69 ms 14348 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 1 ms 340 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 468 KB Output is correct
30 Correct 1 ms 464 KB Output is correct
31 Correct 2 ms 392 KB Output is correct
32 Correct 2 ms 340 KB Output is correct
33 Correct 34 ms 5076 KB Output is correct
34 Correct 81 ms 13252 KB Output is correct
35 Correct 141 ms 19112 KB Output is correct
36 Correct 139 ms 16652 KB Output is correct
37 Correct 87 ms 17224 KB Output is correct
38 Correct 123 ms 19072 KB Output is correct
39 Correct 76 ms 15260 KB Output is correct
40 Correct 82 ms 14500 KB Output is correct
41 Correct 79 ms 14244 KB Output is correct
42 Correct 79 ms 14348 KB Output is correct
43 Correct 73 ms 14300 KB Output is correct
44 Correct 78 ms 14324 KB Output is correct
45 Correct 101 ms 19132 KB Output is correct
46 Correct 75 ms 14632 KB Output is correct
47 Correct 80 ms 13236 KB Output is correct