Submission #1005428

# Submission time Handle Problem Language Result Execution time Memory
1005428 2024-06-22T12:35:22 Z idiotcomputer Potatoes and fertilizers (LMIO19_bulves) C++11
100 / 100
145 ms 11456 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long int 
#define sz size

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	int n;
	cin >> n;

	ll res = 0;
	priority_queue<ll, vector<ll>, greater<ll>> vals;
	vals.push(0);
	ll a,b;
	ll r = 0;
	for (int i = 0; i < n; i++){
		cin >> a >> b;
		a = a-b;
		r += a;
		res += abs(r);
	//	cout << r << " - ";
		if (r >= 0) vals.push(-1*r);
		if (vals.sz() > 1 && vals.top() < -1*r){
		//	cout <<vals.top(); 
			vals.pop();
			if(r>=0)vals.push(-1*r);
		}
	//	cout << '\n';
	}
//	cout << res << "\n";
	while (vals.sz()>0){ res -= (r-max((ll)0,(r+vals.top()))); vals.pop();}
	//cout << "\n";
	cout << res << '\n';
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 9 ms 1036 KB Output is correct
5 Correct 20 ms 1712 KB Output is correct
6 Correct 69 ms 5776 KB Output is correct
7 Correct 61 ms 7404 KB Output is correct
8 Correct 105 ms 9264 KB Output is correct
9 Correct 66 ms 5072 KB Output is correct
10 Correct 66 ms 7884 KB Output is correct
11 Correct 78 ms 6344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 9 ms 1036 KB Output is correct
5 Correct 20 ms 1712 KB Output is correct
6 Correct 69 ms 5776 KB Output is correct
7 Correct 61 ms 7404 KB Output is correct
8 Correct 105 ms 9264 KB Output is correct
9 Correct 66 ms 5072 KB Output is correct
10 Correct 66 ms 7884 KB Output is correct
11 Correct 78 ms 6344 KB Output is correct
12 Correct 29 ms 3036 KB Output is correct
13 Correct 78 ms 6340 KB Output is correct
14 Correct 66 ms 7344 KB Output is correct
15 Correct 124 ms 9352 KB Output is correct
16 Correct 109 ms 7992 KB Output is correct
17 Correct 59 ms 6440 KB Output is correct
18 Correct 1 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 460 KB Output is correct
12 Correct 1 ms 348 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 1 ms 348 KB Output is correct
17 Correct 1 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 468 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 472 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 9 ms 1036 KB Output is correct
12 Correct 20 ms 1712 KB Output is correct
13 Correct 69 ms 5776 KB Output is correct
14 Correct 61 ms 7404 KB Output is correct
15 Correct 105 ms 9264 KB Output is correct
16 Correct 66 ms 5072 KB Output is correct
17 Correct 66 ms 7884 KB Output is correct
18 Correct 78 ms 6344 KB Output is correct
19 Correct 29 ms 3036 KB Output is correct
20 Correct 78 ms 6340 KB Output is correct
21 Correct 66 ms 7344 KB Output is correct
22 Correct 124 ms 9352 KB Output is correct
23 Correct 109 ms 7992 KB Output is correct
24 Correct 59 ms 6440 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 1 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 460 KB Output is correct
33 Correct 30 ms 3024 KB Output is correct
34 Correct 77 ms 8904 KB Output is correct
35 Correct 140 ms 10944 KB Output is correct
36 Correct 138 ms 8660 KB Output is correct
37 Correct 89 ms 9280 KB Output is correct
38 Correct 128 ms 11196 KB Output is correct
39 Correct 77 ms 7360 KB Output is correct
40 Correct 78 ms 6852 KB Output is correct
41 Correct 62 ms 7376 KB Output is correct
42 Correct 62 ms 6856 KB Output is correct
43 Correct 73 ms 7592 KB Output is correct
44 Correct 71 ms 6340 KB Output is correct
45 Correct 145 ms 11456 KB Output is correct
46 Correct 59 ms 6592 KB Output is correct
47 Correct 84 ms 8648 KB Output is correct