Submission #910432

# Submission time Handle Problem Language Result Execution time Memory
910432 2024-01-18T05:03:03 Z pan Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
323 ms 19228 KB
#include <bits/stdc++.h>
//#include "bits_stdc++.h"
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<ll, pi> pii;

int main()
{
	ll ans = 0;
	priority_queue<ll> pq;
	ll n, a, b;
	cin >> n;
	ll dif[n+1], ps[n+1];
	ps[0]=0;
	for (ll i=1; i<=n; ++i)
	{
		cin >> a >> b;
		dif[i] = a-b;
		ps[i]= ps[i-1] + dif[i];
		ans +=abs(ps[i]);
		pq.push(max(0LL, ps[i]));
		pq.push(max(0LL, ps[i]));
		pq.pop();

	}
	for (ll i=0; i<n; ++i) {ans-=min(pq.top(), ps[n]); pq.pop();}
	cout << ans << endl;
	
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 20 ms 2068 KB Output is correct
5 Correct 46 ms 3540 KB Output is correct
6 Correct 209 ms 9792 KB Output is correct
7 Correct 261 ms 19228 KB Output is correct
8 Correct 258 ms 17252 KB Output is correct
9 Correct 216 ms 16544 KB Output is correct
10 Correct 175 ms 14064 KB Output is correct
11 Correct 175 ms 14304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 20 ms 2068 KB Output is correct
5 Correct 46 ms 3540 KB Output is correct
6 Correct 209 ms 9792 KB Output is correct
7 Correct 261 ms 19228 KB Output is correct
8 Correct 258 ms 17252 KB Output is correct
9 Correct 216 ms 16544 KB Output is correct
10 Correct 175 ms 14064 KB Output is correct
11 Correct 175 ms 14304 KB Output is correct
12 Correct 74 ms 5168 KB Output is correct
13 Correct 202 ms 13556 KB Output is correct
14 Correct 264 ms 19080 KB Output is correct
15 Correct 266 ms 17140 KB Output is correct
16 Correct 262 ms 16772 KB Output is correct
17 Correct 158 ms 14752 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 448 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 448 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 348 KB Output is correct
14 Correct 3 ms 344 KB Output is correct
15 Correct 2 ms 348 KB Output is correct
16 Correct 2 ms 348 KB Output is correct
17 Correct 2 ms 524 KB Output is correct
18 Correct 2 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 2 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 344 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 2 ms 448 KB Output is correct
8 Correct 2 ms 600 KB Output is correct
9 Correct 2 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 20 ms 2068 KB Output is correct
12 Correct 46 ms 3540 KB Output is correct
13 Correct 209 ms 9792 KB Output is correct
14 Correct 261 ms 19228 KB Output is correct
15 Correct 258 ms 17252 KB Output is correct
16 Correct 216 ms 16544 KB Output is correct
17 Correct 175 ms 14064 KB Output is correct
18 Correct 175 ms 14304 KB Output is correct
19 Correct 74 ms 5168 KB Output is correct
20 Correct 202 ms 13556 KB Output is correct
21 Correct 264 ms 19080 KB Output is correct
22 Correct 266 ms 17140 KB Output is correct
23 Correct 262 ms 16772 KB Output is correct
24 Correct 158 ms 14752 KB Output is correct
25 Correct 2 ms 348 KB Output is correct
26 Correct 2 ms 348 KB Output is correct
27 Correct 3 ms 344 KB Output is correct
28 Correct 2 ms 348 KB Output is correct
29 Correct 2 ms 348 KB Output is correct
30 Correct 2 ms 524 KB Output is correct
31 Correct 2 ms 348 KB Output is correct
32 Correct 2 ms 348 KB Output is correct
33 Correct 81 ms 5320 KB Output is correct
34 Correct 189 ms 14528 KB Output is correct
35 Correct 323 ms 18812 KB Output is correct
36 Correct 277 ms 16584 KB Output is correct
37 Correct 254 ms 17188 KB Output is correct
38 Correct 323 ms 19068 KB Output is correct
39 Correct 192 ms 15220 KB Output is correct
40 Correct 204 ms 15364 KB Output is correct
41 Correct 165 ms 15036 KB Output is correct
42 Correct 166 ms 15516 KB Output is correct
43 Correct 168 ms 14444 KB Output is correct
44 Correct 170 ms 14420 KB Output is correct
45 Correct 306 ms 18868 KB Output is correct
46 Correct 194 ms 14572 KB Output is correct
47 Correct 180 ms 13844 KB Output is correct