답안 #744492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
744492 2023-05-18T15:47:40 Z Szymon_25 Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
422 ms 15192 KB
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int n;

ll f = 0;         
priority_queue<ll> Q;  //punkty przegiecia DP

int main() {
	cin >> n;
	
	vector<ll> pref(n+1);
	
	for (int i=1; i<=n; i++) {
		int a, b;
		cin >> a >> b;
		pref[i] = a - b + pref[i - 1];
	}
	
	for (int i=1; i<n; i++){
		if(pref[i] < 0){
			f -= pref[i]; 
			pref[i] = 0;
		}
		f += pref[i];
		Q.push(pref[i]);
		Q.push(pref[i]);
		Q.pop();
	}

	while (Q.size()) {
		ll tmp = Q.top();
		Q.pop();
		f -= min(tmp, pref[n]);
	}

	cout << f << "\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 27 ms 1572 KB Output is correct
5 Correct 56 ms 2864 KB Output is correct
6 Correct 202 ms 7724 KB Output is correct
7 Correct 341 ms 15192 KB Output is correct
8 Correct 326 ms 13236 KB Output is correct
9 Correct 288 ms 12764 KB Output is correct
10 Correct 207 ms 10376 KB Output is correct
11 Correct 220 ms 10380 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 27 ms 1572 KB Output is correct
5 Correct 56 ms 2864 KB Output is correct
6 Correct 202 ms 7724 KB Output is correct
7 Correct 341 ms 15192 KB Output is correct
8 Correct 326 ms 13236 KB Output is correct
9 Correct 288 ms 12764 KB Output is correct
10 Correct 207 ms 10376 KB Output is correct
11 Correct 220 ms 10380 KB Output is correct
12 Correct 101 ms 4072 KB Output is correct
13 Correct 266 ms 10940 KB Output is correct
14 Correct 363 ms 15184 KB Output is correct
15 Correct 399 ms 13308 KB Output is correct
16 Correct 340 ms 12588 KB Output is correct
17 Correct 225 ms 10456 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 2 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 2 ms 212 KB Output is correct
6 Correct 1 ms 308 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 340 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 308 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 340 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 3 ms 340 KB Output is correct
13 Correct 3 ms 364 KB Output is correct
14 Correct 12 ms 312 KB Output is correct
15 Correct 3 ms 340 KB Output is correct
16 Correct 3 ms 340 KB Output is correct
17 Correct 2 ms 316 KB Output is correct
18 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Correct 2 ms 340 KB Output is correct
3 Correct 3 ms 356 KB Output is correct
4 Correct 1 ms 212 KB Output is correct
5 Correct 2 ms 212 KB Output is correct
6 Correct 1 ms 308 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 340 KB Output is correct
10 Correct 2 ms 308 KB Output is correct
11 Correct 27 ms 1572 KB Output is correct
12 Correct 56 ms 2864 KB Output is correct
13 Correct 202 ms 7724 KB Output is correct
14 Correct 341 ms 15192 KB Output is correct
15 Correct 326 ms 13236 KB Output is correct
16 Correct 288 ms 12764 KB Output is correct
17 Correct 207 ms 10376 KB Output is correct
18 Correct 220 ms 10380 KB Output is correct
19 Correct 101 ms 4072 KB Output is correct
20 Correct 266 ms 10940 KB Output is correct
21 Correct 363 ms 15184 KB Output is correct
22 Correct 399 ms 13308 KB Output is correct
23 Correct 340 ms 12588 KB Output is correct
24 Correct 225 ms 10456 KB Output is correct
25 Correct 3 ms 340 KB Output is correct
26 Correct 3 ms 364 KB Output is correct
27 Correct 12 ms 312 KB Output is correct
28 Correct 3 ms 340 KB Output is correct
29 Correct 3 ms 340 KB Output is correct
30 Correct 2 ms 316 KB Output is correct
31 Correct 4 ms 340 KB Output is correct
32 Correct 1 ms 340 KB Output is correct
33 Correct 93 ms 4064 KB Output is correct
34 Correct 256 ms 10920 KB Output is correct
35 Correct 422 ms 15192 KB Output is correct
36 Correct 381 ms 12900 KB Output is correct
37 Correct 362 ms 13244 KB Output is correct
38 Correct 403 ms 15188 KB Output is correct
39 Correct 250 ms 11324 KB Output is correct
40 Correct 298 ms 10848 KB Output is correct
41 Correct 219 ms 10336 KB Output is correct
42 Correct 229 ms 10372 KB Output is correct
43 Correct 210 ms 10328 KB Output is correct
44 Correct 272 ms 10336 KB Output is correct
45 Correct 383 ms 15164 KB Output is correct
46 Correct 251 ms 10716 KB Output is correct
47 Correct 233 ms 10228 KB Output is correct