답안 #715951

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
715951 2023-03-28T14:51:17 Z amunduzbaev Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
143 ms 19116 KB
#include "bits/stdc++.h"
using namespace std;

#define ar array
typedef long long ll;
#define int ll

const int N = 5e5 + 5;
int a[N], b[N];

signed main(){
	ios::sync_with_stdio(0); cin.tie(0);
	
	int n; cin >> n;
	int res = 0;
	for(int i=1;i<=n;i++){
		cin >> a[i] >> b[i];
		a[i] -= b[i];
		a[i] += a[i-1];
	}
	
	int mx = a[n];
	assert(0 <= mx);
	for(int i=1;i<=n;i++){
		if(a[i] < 0){
			res -= a[i];
			a[i] = 0;
		}
		if(a[i] > mx){
			res += (a[i] - mx);
			a[i] = mx;
		}
	}
	
	priority_queue<int> q;
	for(int i=1;i<=n;i++){
		q.push(a[i]);
		if(a[i] < q.top()){
			res += (q.top() - a[i]);
			q.pop(); q.push(a[i]);
		}
	}
	
	cout<<res<<"\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2008 KB Output is correct
5 Correct 14 ms 3668 KB Output is correct
6 Correct 45 ms 9712 KB Output is correct
7 Correct 96 ms 19116 KB Output is correct
8 Correct 82 ms 17236 KB Output is correct
9 Correct 73 ms 16504 KB Output is correct
10 Correct 57 ms 14264 KB Output is correct
11 Correct 51 ms 14296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 7 ms 2008 KB Output is correct
5 Correct 14 ms 3668 KB Output is correct
6 Correct 45 ms 9712 KB Output is correct
7 Correct 96 ms 19116 KB Output is correct
8 Correct 82 ms 17236 KB Output is correct
9 Correct 73 ms 16504 KB Output is correct
10 Correct 57 ms 14264 KB Output is correct
11 Correct 51 ms 14296 KB Output is correct
12 Correct 25 ms 5072 KB Output is correct
13 Correct 73 ms 13200 KB Output is correct
14 Correct 97 ms 19048 KB Output is correct
15 Correct 75 ms 17264 KB Output is correct
16 Correct 71 ms 16580 KB Output is correct
17 Correct 70 ms 14276 KB Output is correct
18 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 212 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 344 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 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 344 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 344 KB Output is correct
13 Correct 2 ms 468 KB Output is correct
14 Correct 1 ms 468 KB Output is correct
15 Correct 1 ms 468 KB Output is correct
16 Correct 2 ms 468 KB Output is correct
17 Correct 1 ms 340 KB Output is correct
18 Correct 2 ms 428 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 468 KB Output is correct
4 Correct 1 ms 212 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 344 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 7 ms 2008 KB Output is correct
12 Correct 14 ms 3668 KB Output is correct
13 Correct 45 ms 9712 KB Output is correct
14 Correct 96 ms 19116 KB Output is correct
15 Correct 82 ms 17236 KB Output is correct
16 Correct 73 ms 16504 KB Output is correct
17 Correct 57 ms 14264 KB Output is correct
18 Correct 51 ms 14296 KB Output is correct
19 Correct 25 ms 5072 KB Output is correct
20 Correct 73 ms 13200 KB Output is correct
21 Correct 97 ms 19048 KB Output is correct
22 Correct 75 ms 17264 KB Output is correct
23 Correct 71 ms 16580 KB Output is correct
24 Correct 70 ms 14276 KB Output is correct
25 Correct 1 ms 344 KB Output is correct
26 Correct 2 ms 468 KB Output is correct
27 Correct 1 ms 468 KB Output is correct
28 Correct 1 ms 468 KB Output is correct
29 Correct 2 ms 468 KB Output is correct
30 Correct 1 ms 340 KB Output is correct
31 Correct 2 ms 428 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 41 ms 5048 KB Output is correct
34 Correct 91 ms 13288 KB Output is correct
35 Correct 141 ms 19028 KB Output is correct
36 Correct 133 ms 16680 KB Output is correct
37 Correct 84 ms 17352 KB Output is correct
38 Correct 143 ms 19064 KB Output is correct
39 Correct 81 ms 15228 KB Output is correct
40 Correct 112 ms 14440 KB Output is correct
41 Correct 76 ms 14280 KB Output is correct
42 Correct 76 ms 14432 KB Output is correct
43 Correct 85 ms 14256 KB Output is correct
44 Correct 85 ms 14232 KB Output is correct
45 Correct 112 ms 19012 KB Output is correct
46 Correct 67 ms 14624 KB Output is correct
47 Correct 82 ms 13232 KB Output is correct