Submission #772259

# Submission time Handle Problem Language Result Execution time Memory
772259 2023-07-03T20:32:49 Z radoslav11 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
402 ms 15196 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

int N;
ll fst = 0;                 // value of DP function at 0
priority_queue<ll> points;  // points where DP function changes slope

int main() {
	cin >> N;
	vector<ll> dif(N + 1);
	for (int i = 1; i <= N; ++i) {
		int a, b;
		cin >> a >> b;
		dif[i] = a - b + dif[i - 1];
	}
	assert(dif[N] >= 0);  // assume solution exists
	for (int i = 1; i < N; ++i) {
		if (dif[i] < 0) fst -= dif[i], dif[i] = 0;
		fst += dif[i];
		points.push(dif[i]);
		points.push(dif[i]);
		points.pop();
	}
	while (points.size()) {
		ll a = points.top();
		points.pop();
		fst -= min(a, dif[N]);
	}
	cout << fst << "\n";
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 21 ms 1500 KB Output is correct
5 Correct 45 ms 2392 KB Output is correct
6 Correct 154 ms 4824 KB Output is correct
7 Correct 285 ms 9008 KB Output is correct
8 Correct 269 ms 8924 KB Output is correct
9 Correct 223 ms 12620 KB Output is correct
10 Correct 173 ms 10316 KB Output is correct
11 Correct 183 ms 10404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 21 ms 1500 KB Output is correct
5 Correct 45 ms 2392 KB Output is correct
6 Correct 154 ms 4824 KB Output is correct
7 Correct 285 ms 9008 KB Output is correct
8 Correct 269 ms 8924 KB Output is correct
9 Correct 223 ms 12620 KB Output is correct
10 Correct 173 ms 10316 KB Output is correct
11 Correct 183 ms 10404 KB Output is correct
12 Correct 80 ms 4056 KB Output is correct
13 Correct 182 ms 10928 KB Output is correct
14 Correct 267 ms 15172 KB Output is correct
15 Correct 265 ms 13244 KB Output is correct
16 Correct 263 ms 12620 KB Output is correct
17 Correct 169 ms 10320 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 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 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 340 KB Output is correct
14 Correct 2 ms 364 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 2 ms 340 KB Output is correct
17 Correct 1 ms 308 KB Output is correct
18 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 2 ms 360 KB Output is correct
4 Correct 0 ms 300 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 340 KB Output is correct
8 Correct 2 ms 340 KB Output is correct
9 Correct 2 ms 312 KB Output is correct
10 Correct 2 ms 340 KB Output is correct
11 Correct 21 ms 1500 KB Output is correct
12 Correct 45 ms 2392 KB Output is correct
13 Correct 154 ms 4824 KB Output is correct
14 Correct 285 ms 9008 KB Output is correct
15 Correct 269 ms 8924 KB Output is correct
16 Correct 223 ms 12620 KB Output is correct
17 Correct 173 ms 10316 KB Output is correct
18 Correct 183 ms 10404 KB Output is correct
19 Correct 80 ms 4056 KB Output is correct
20 Correct 182 ms 10928 KB Output is correct
21 Correct 267 ms 15172 KB Output is correct
22 Correct 265 ms 13244 KB Output is correct
23 Correct 263 ms 12620 KB Output is correct
24 Correct 169 ms 10320 KB Output is correct
25 Correct 2 ms 340 KB Output is correct
26 Correct 2 ms 340 KB Output is correct
27 Correct 2 ms 364 KB Output is correct
28 Correct 2 ms 340 KB Output is correct
29 Correct 2 ms 340 KB Output is correct
30 Correct 1 ms 308 KB Output is correct
31 Correct 2 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 75 ms 4040 KB Output is correct
34 Correct 186 ms 10812 KB Output is correct
35 Correct 402 ms 15196 KB Output is correct
36 Correct 283 ms 12720 KB Output is correct
37 Correct 267 ms 13268 KB Output is correct
38 Correct 321 ms 15192 KB Output is correct
39 Correct 200 ms 11380 KB Output is correct
40 Correct 217 ms 10844 KB Output is correct
41 Correct 174 ms 10300 KB Output is correct
42 Correct 172 ms 10300 KB Output is correct
43 Correct 168 ms 10400 KB Output is correct
44 Correct 181 ms 10288 KB Output is correct
45 Correct 307 ms 15064 KB Output is correct
46 Correct 203 ms 10624 KB Output is correct
47 Correct 187 ms 10228 KB Output is correct