Submission #565928

# Submission time Handle Problem Language Result Execution time Memory
565928 2022-05-21T14:42:37 Z sofapuden Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
204 ms 11176 KB
#include<bits/stdc++.h>
 
using namespace std;

typedef long long ll;

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	priority_queue<ll> pq;
	ll dif = 0;
	ll ans = 0;
	for(int i = 0; i < n; ++i){
		int a, b; cin >> a >> b;
		dif+=a-b;
		ans+=abs(dif);
		pq.push(max(0ll,dif));
		pq.push(max(0ll,dif));
		pq.pop();
	}
	while(pq.size()){
		auto x = pq.top(); pq.pop();
		ans-=min(x,dif);
	}
	cout << ans << '\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 13 ms 1236 KB Output is correct
5 Correct 30 ms 1996 KB Output is correct
6 Correct 97 ms 5680 KB Output is correct
7 Correct 131 ms 11040 KB Output is correct
8 Correct 167 ms 9248 KB Output is correct
9 Correct 140 ms 8504 KB Output is correct
10 Correct 108 ms 6308 KB Output is correct
11 Correct 113 ms 6208 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 13 ms 1236 KB Output is correct
5 Correct 30 ms 1996 KB Output is correct
6 Correct 97 ms 5680 KB Output is correct
7 Correct 131 ms 11040 KB Output is correct
8 Correct 167 ms 9248 KB Output is correct
9 Correct 140 ms 8504 KB Output is correct
10 Correct 108 ms 6308 KB Output is correct
11 Correct 113 ms 6208 KB Output is correct
12 Correct 47 ms 3048 KB Output is correct
13 Correct 115 ms 8244 KB Output is correct
14 Correct 147 ms 11096 KB Output is correct
15 Correct 167 ms 9208 KB Output is correct
16 Correct 187 ms 8584 KB Output is correct
17 Correct 115 ms 6204 KB Output is correct
18 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 320 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 320 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 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 1 ms 340 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 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 320 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 13 ms 1236 KB Output is correct
12 Correct 30 ms 1996 KB Output is correct
13 Correct 97 ms 5680 KB Output is correct
14 Correct 131 ms 11040 KB Output is correct
15 Correct 167 ms 9248 KB Output is correct
16 Correct 140 ms 8504 KB Output is correct
17 Correct 108 ms 6308 KB Output is correct
18 Correct 113 ms 6208 KB Output is correct
19 Correct 47 ms 3048 KB Output is correct
20 Correct 115 ms 8244 KB Output is correct
21 Correct 147 ms 11096 KB Output is correct
22 Correct 167 ms 9208 KB Output is correct
23 Correct 187 ms 8584 KB Output is correct
24 Correct 115 ms 6204 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 340 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 1 ms 340 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 1 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 46 ms 3012 KB Output is correct
34 Correct 116 ms 8252 KB Output is correct
35 Correct 204 ms 11020 KB Output is correct
36 Correct 188 ms 8636 KB Output is correct
37 Correct 172 ms 9144 KB Output is correct
38 Correct 188 ms 11176 KB Output is correct
39 Correct 128 ms 7224 KB Output is correct
40 Correct 143 ms 6840 KB Output is correct
41 Correct 110 ms 6288 KB Output is correct
42 Correct 109 ms 6200 KB Output is correct
43 Correct 111 ms 6328 KB Output is correct
44 Correct 116 ms 6200 KB Output is correct
45 Correct 185 ms 10984 KB Output is correct
46 Correct 139 ms 6588 KB Output is correct
47 Correct 129 ms 6536 KB Output is correct