답안 #697959

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
697959 2023-02-11T15:16:22 Z siewjh Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
139 ms 15312 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int nums; cin >> nums;
	priority_queue<ll> pq;
	vector<ll> pref(nums + 1);
	pref[0] = 0;
	for (int i = 1; i <= nums; i++){
		ll s, d; cin >> s >> d;
		pref[i] = pref[i - 1] + s - d;
	}
	ll ans = 0;
	for (int i = 1; i <= nums; i++){
		if (pref[i] < 0) {
			ans -= pref[i];
			pref[i] = 0;
		}
		else if (pref[i] > pref[nums]){
			ans += pref[i] - pref[nums];
			pref[i] = pref[nums];
		}
		pq.push(pref[i]);
		pq.push(pref[i]);
		ans += pq.top() - pref[i];
		pq.pop();
	}
	cout << ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 8 ms 1608 KB Output is correct
5 Correct 17 ms 2900 KB Output is correct
6 Correct 55 ms 7952 KB Output is correct
7 Correct 113 ms 15312 KB Output is correct
8 Correct 87 ms 13296 KB Output is correct
9 Correct 82 ms 12612 KB Output is correct
10 Correct 69 ms 10364 KB Output is correct
11 Correct 70 ms 10372 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 8 ms 1608 KB Output is correct
5 Correct 17 ms 2900 KB Output is correct
6 Correct 55 ms 7952 KB Output is correct
7 Correct 113 ms 15312 KB Output is correct
8 Correct 87 ms 13296 KB Output is correct
9 Correct 82 ms 12612 KB Output is correct
10 Correct 69 ms 10364 KB Output is correct
11 Correct 70 ms 10372 KB Output is correct
12 Correct 30 ms 4112 KB Output is correct
13 Correct 85 ms 10868 KB Output is correct
14 Correct 101 ms 15216 KB Output is correct
15 Correct 86 ms 13304 KB Output is correct
16 Correct 85 ms 12660 KB Output is correct
17 Correct 86 ms 10436 KB Output is correct
18 Correct 2 ms 436 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 2 ms 436 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 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 2 ms 436 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 340 KB Output is correct
14 Correct 2 ms 392 KB Output is correct
15 Correct 1 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
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 1 ms 328 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 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 8 ms 1608 KB Output is correct
12 Correct 17 ms 2900 KB Output is correct
13 Correct 55 ms 7952 KB Output is correct
14 Correct 113 ms 15312 KB Output is correct
15 Correct 87 ms 13296 KB Output is correct
16 Correct 82 ms 12612 KB Output is correct
17 Correct 69 ms 10364 KB Output is correct
18 Correct 70 ms 10372 KB Output is correct
19 Correct 30 ms 4112 KB Output is correct
20 Correct 85 ms 10868 KB Output is correct
21 Correct 101 ms 15216 KB Output is correct
22 Correct 86 ms 13304 KB Output is correct
23 Correct 85 ms 12660 KB Output is correct
24 Correct 86 ms 10436 KB Output is correct
25 Correct 1 ms 340 KB Output is correct
26 Correct 1 ms 340 KB Output is correct
27 Correct 2 ms 392 KB Output is correct
28 Correct 1 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 2 ms 436 KB Output is correct
33 Correct 40 ms 4136 KB Output is correct
34 Correct 81 ms 10848 KB Output is correct
35 Correct 139 ms 15228 KB Output is correct
36 Correct 128 ms 12792 KB Output is correct
37 Correct 109 ms 13296 KB Output is correct
38 Correct 132 ms 15220 KB Output is correct
39 Correct 84 ms 11380 KB Output is correct
40 Correct 112 ms 10948 KB Output is correct
41 Correct 82 ms 10360 KB Output is correct
42 Correct 96 ms 10320 KB Output is correct
43 Correct 82 ms 10436 KB Output is correct
44 Correct 80 ms 10364 KB Output is correct
45 Correct 109 ms 15096 KB Output is correct
46 Correct 107 ms 10732 KB Output is correct
47 Correct 100 ms 10180 KB Output is correct