Submission #545740

# Submission time Handle Problem Language Result Execution time Memory
545740 2022-04-05T10:28:11 Z pure_mem Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
217 ms 23008 KB
#pragma GCC optimize("Ofast")

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define X first
#define Y second
#define MP make_pair

using namespace std;

const int N = 5e5 + 1;
const ll INF = 1e12 + 1;

int n;
ll a[N], b[N], dif[N];

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin >> n;
	for(int i = 1;i <= n;i++)
 		cin >> a[i] >> b[i], dif[i] = dif[i - 1] + a[i] - b[i];

   	ll ans = 0;
   	priority_queue<ll> dp;

 	for(int i = 1;i <= n;i++) {
 		ans += abs(dif[i]);
 		if(dif[i] < 0)
 			dif[i] = 0;	

 		dp.push(dif[i]);
 		dp.push(dif[i]);
 		dp.pop();	
 	}

 	for(;!dp.empty();) {
 	//	cerr << dp.top() << " " << dif[n] << "\n"; 
 		ans -= min(dp.top(), dif[n]);
 		dp.pop();
 	}

	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 26 ms 2384 KB Output is correct
5 Correct 29 ms 4460 KB Output is correct
6 Correct 98 ms 11720 KB Output is correct
7 Correct 157 ms 22940 KB Output is correct
8 Correct 173 ms 21088 KB Output is correct
9 Correct 171 ms 20448 KB Output is correct
10 Correct 111 ms 18236 KB Output is correct
11 Correct 118 ms 18152 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 26 ms 2384 KB Output is correct
5 Correct 29 ms 4460 KB Output is correct
6 Correct 98 ms 11720 KB Output is correct
7 Correct 157 ms 22940 KB Output is correct
8 Correct 173 ms 21088 KB Output is correct
9 Correct 171 ms 20448 KB Output is correct
10 Correct 111 ms 18236 KB Output is correct
11 Correct 118 ms 18152 KB Output is correct
12 Correct 46 ms 6072 KB Output is correct
13 Correct 123 ms 15664 KB Output is correct
14 Correct 197 ms 23008 KB Output is correct
15 Correct 196 ms 21196 KB Output is correct
16 Correct 217 ms 20500 KB Output is correct
17 Correct 117 ms 18236 KB Output is correct
18 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 324 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 472 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 1 ms 324 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 472 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 1 ms 468 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 2 ms 472 KB Output is correct
14 Correct 2 ms 468 KB Output is correct
15 Correct 2 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 2 ms 468 KB Output is correct
18 Correct 1 ms 404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 468 KB Output is correct
3 Correct 2 ms 392 KB Output is correct
4 Correct 1 ms 324 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 472 KB Output is correct
8 Correct 1 ms 468 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 1 ms 468 KB Output is correct
11 Correct 26 ms 2384 KB Output is correct
12 Correct 29 ms 4460 KB Output is correct
13 Correct 98 ms 11720 KB Output is correct
14 Correct 157 ms 22940 KB Output is correct
15 Correct 173 ms 21088 KB Output is correct
16 Correct 171 ms 20448 KB Output is correct
17 Correct 111 ms 18236 KB Output is correct
18 Correct 118 ms 18152 KB Output is correct
19 Correct 46 ms 6072 KB Output is correct
20 Correct 123 ms 15664 KB Output is correct
21 Correct 197 ms 23008 KB Output is correct
22 Correct 196 ms 21196 KB Output is correct
23 Correct 217 ms 20500 KB Output is correct
24 Correct 117 ms 18236 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 2 ms 472 KB Output is correct
27 Correct 2 ms 468 KB Output is correct
28 Correct 2 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 2 ms 468 KB Output is correct
31 Correct 1 ms 404 KB Output is correct
32 Correct 1 ms 468 KB Output is correct
33 Correct 59 ms 6140 KB Output is correct
34 Correct 126 ms 15672 KB Output is correct
35 Correct 207 ms 22976 KB Output is correct
36 Correct 213 ms 20564 KB Output is correct
37 Correct 172 ms 21192 KB Output is correct
38 Correct 198 ms 22988 KB Output is correct
39 Correct 147 ms 19172 KB Output is correct
40 Correct 150 ms 17988 KB Output is correct
41 Correct 137 ms 18172 KB Output is correct
42 Correct 108 ms 18260 KB Output is correct
43 Correct 114 ms 18172 KB Output is correct
44 Correct 143 ms 18244 KB Output is correct
45 Correct 191 ms 22976 KB Output is correct
46 Correct 139 ms 18576 KB Output is correct
47 Correct 157 ms 16288 KB Output is correct