답안 #476577

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
476577 2021-09-27T16:52:36 Z idiot123 Potatoes and fertilizers (LMIO19_bulves) C++14
100 / 100
204 ms 19316 KB
#include<bits/stdc++.h>

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int N; cin>>N;
	vector<long long> t(N);
	for(int i = 0; i < N; i++){
		int a, b; cin>>a>>b;
		t[i] = a - b;
	}
	priority_queue<long long, vector<long long>, greater<long long>> q;
	for(int i = 0; i < N; i++)q.push(0);
	long long shift = 0;
	long long val = 0;
	for(int i = 1; i <= N; i++){
		//wywalamy pierwszy punkt
		q.pop();
		//przesuwamy
		shift += t[i-1];
		//pobieramy pozycje pierwszego punktu
		long long x = q.top() + shift;
		if(x <= 0){
			val += abs(x);
		}
		q.push(-shift); q.push(-shift);
	}
	long long x = q.top() + shift;
	long long result;
	if(x >= 0){
		result = val + x;
	}else{
		result = val;
		int slope = 0;
		q.pop();
		while(q.top() + shift < 0){
			result += slope * (q.top() + shift - x);
			x = q.top() + shift;
			q.pop();
			slope++;
		}
		result += -slope * x;
	}
	cout<<result;
	return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 15 ms 1864 KB Output is correct
5 Correct 31 ms 3212 KB Output is correct
6 Correct 106 ms 6496 KB Output is correct
7 Correct 158 ms 12540 KB Output is correct
8 Correct 175 ms 12548 KB Output is correct
9 Correct 158 ms 16744 KB Output is correct
10 Correct 121 ms 14524 KB Output is correct
11 Correct 116 ms 14448 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 15 ms 1864 KB Output is correct
5 Correct 31 ms 3212 KB Output is correct
6 Correct 106 ms 6496 KB Output is correct
7 Correct 158 ms 12540 KB Output is correct
8 Correct 175 ms 12548 KB Output is correct
9 Correct 158 ms 16744 KB Output is correct
10 Correct 121 ms 14524 KB Output is correct
11 Correct 116 ms 14448 KB Output is correct
12 Correct 50 ms 5120 KB Output is correct
13 Correct 137 ms 15168 KB Output is correct
14 Correct 143 ms 19316 KB Output is correct
15 Correct 191 ms 17464 KB Output is correct
16 Correct 204 ms 16748 KB Output is correct
17 Correct 110 ms 14444 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 15 ms 1864 KB Output is correct
12 Correct 31 ms 3212 KB Output is correct
13 Correct 106 ms 6496 KB Output is correct
14 Correct 158 ms 12540 KB Output is correct
15 Correct 175 ms 12548 KB Output is correct
16 Correct 158 ms 16744 KB Output is correct
17 Correct 121 ms 14524 KB Output is correct
18 Correct 116 ms 14448 KB Output is correct
19 Correct 50 ms 5120 KB Output is correct
20 Correct 137 ms 15168 KB Output is correct
21 Correct 143 ms 19316 KB Output is correct
22 Correct 191 ms 17464 KB Output is correct
23 Correct 204 ms 16748 KB Output is correct
24 Correct 110 ms 14444 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 332 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 1 ms 332 KB Output is correct
30 Correct 1 ms 332 KB Output is correct
31 Correct 1 ms 332 KB Output is correct
32 Correct 1 ms 332 KB Output is correct
33 Correct 42 ms 5120 KB Output is correct
34 Correct 94 ms 15020 KB Output is correct
35 Correct 177 ms 19300 KB Output is correct
36 Correct 157 ms 16868 KB Output is correct
37 Correct 164 ms 17464 KB Output is correct
38 Correct 152 ms 19296 KB Output is correct
39 Correct 114 ms 15476 KB Output is correct
40 Correct 121 ms 15032 KB Output is correct
41 Correct 112 ms 14432 KB Output is correct
42 Correct 124 ms 14448 KB Output is correct
43 Correct 111 ms 14520 KB Output is correct
44 Correct 98 ms 14432 KB Output is correct
45 Correct 187 ms 19308 KB Output is correct
46 Correct 145 ms 14776 KB Output is correct
47 Correct 102 ms 14356 KB Output is correct