답안 #253303

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
253303 2020-07-27T16:36:59 Z DystoriaX Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
241 ms 7532 KB
#include <bits/stdc++.h>

using namespace std;

int n;
long long lazy, vc, slope;
priority_queue<long long, vector<long long>, greater<long long> > pq;

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	cin >> n;

	pq.push(0);

	for(int i = 1; i <= n; i++){
		int a, b;
		cin >> a >> b;

		int d = a - b;

		lazy += d;

		if(pq.top() + lazy < d){
			vc += d - (pq.top() + lazy);

			if(pq.top() != 0) pq.pop();

			if(d <= lazy){
				pq.push(d - lazy);
				pq.push(d - lazy);
			}
		} else {
			pq.push(d - lazy);
		}
	}

	long long cur = pq.top() + lazy;

	slope = 0;
	while(!pq.empty()){
		long long nxt = pq.top() + lazy; pq.pop();

		nxt = min(nxt, 0LL);

		vc += (nxt - cur) * slope;
		slope++; cur = nxt;
	}

	if(cur != 0) vc += -cur * slope;

	cout << vc << "\n";

	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 15 ms 1024 KB Output is correct
5 Correct 32 ms 1632 KB Output is correct
6 Correct 117 ms 5100 KB Output is correct
7 Correct 123 ms 3448 KB Output is correct
8 Correct 180 ms 7404 KB Output is correct
9 Correct 118 ms 3700 KB Output is correct
10 Correct 121 ms 6296 KB Output is correct
11 Correct 126 ms 6392 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 15 ms 1024 KB Output is correct
5 Correct 32 ms 1632 KB Output is correct
6 Correct 117 ms 5100 KB Output is correct
7 Correct 123 ms 3448 KB Output is correct
8 Correct 180 ms 7404 KB Output is correct
9 Correct 118 ms 3700 KB Output is correct
10 Correct 121 ms 6296 KB Output is correct
11 Correct 126 ms 6392 KB Output is correct
12 Correct 54 ms 3060 KB Output is correct
13 Correct 132 ms 5096 KB Output is correct
14 Correct 119 ms 3448 KB Output is correct
15 Correct 173 ms 7400 KB Output is correct
16 Correct 199 ms 7272 KB Output is correct
17 Correct 104 ms 6368 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 0 ms 384 KB Output is correct
4 Correct 2 ms 384 KB Output is correct
5 Correct 1 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 2 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 1 ms 384 KB Output is correct
12 Correct 2 ms 384 KB Output is correct
13 Correct 2 ms 384 KB Output is correct
14 Correct 1 ms 384 KB Output is correct
15 Correct 1 ms 384 KB Output is correct
16 Correct 1 ms 384 KB Output is correct
17 Correct 1 ms 384 KB Output is correct
18 Correct 1 ms 384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 384 KB Output is correct
2 Correct 1 ms 384 KB Output is correct
3 Correct 1 ms 384 KB Output is correct
4 Correct 0 ms 384 KB Output is correct
5 Correct 2 ms 384 KB Output is correct
6 Correct 1 ms 384 KB Output is correct
7 Correct 1 ms 384 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 2 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 15 ms 1024 KB Output is correct
12 Correct 32 ms 1632 KB Output is correct
13 Correct 117 ms 5100 KB Output is correct
14 Correct 123 ms 3448 KB Output is correct
15 Correct 180 ms 7404 KB Output is correct
16 Correct 118 ms 3700 KB Output is correct
17 Correct 121 ms 6296 KB Output is correct
18 Correct 126 ms 6392 KB Output is correct
19 Correct 54 ms 3060 KB Output is correct
20 Correct 132 ms 5096 KB Output is correct
21 Correct 119 ms 3448 KB Output is correct
22 Correct 173 ms 7400 KB Output is correct
23 Correct 199 ms 7272 KB Output is correct
24 Correct 104 ms 6368 KB Output is correct
25 Correct 1 ms 384 KB Output is correct
26 Correct 2 ms 384 KB Output is correct
27 Correct 2 ms 384 KB Output is correct
28 Correct 1 ms 384 KB Output is correct
29 Correct 1 ms 384 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 384 KB Output is correct
32 Correct 55 ms 3056 KB Output is correct
33 Correct 146 ms 7532 KB Output is correct
34 Correct 241 ms 7400 KB Output is correct
35 Correct 232 ms 7264 KB Output is correct
36 Correct 168 ms 7400 KB Output is correct
37 Correct 238 ms 7272 KB Output is correct
38 Correct 130 ms 7136 KB Output is correct
39 Correct 152 ms 6756 KB Output is correct
40 Correct 118 ms 6372 KB Output is correct
41 Correct 123 ms 6368 KB Output is correct
42 Correct 125 ms 6368 KB Output is correct
43 Correct 125 ms 6368 KB Output is correct
44 Correct 220 ms 7344 KB Output is correct
45 Correct 107 ms 6624 KB Output is correct
46 Correct 146 ms 6632 KB Output is correct
47 Correct 1 ms 384 KB Output is correct