답안 #473504

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
473504 2021-09-15T15:48:37 Z Fgdxx Potatoes and fertilizers (LMIO19_bulves) C++17
30 / 100
403 ms 8872 KB
#include<bits/stdc++.h>

using namespace std;

int main(){
	int n; cin>>n;
	priority_queue<int, vector<int>, greater<int>> q;
	for(int i = 0; i < 2*n; i++)q.push(0);
	long long shift = 0;
	long long val = 0;
	for(int i = 0; i < n; i++){
		int a, b; cin>>a>>b;
		long long x1 = q.top(); q.pop(); long long x2 = q.top();//pochodna na x1, x2 0 wiec x1 niepotrzebne
		shift += a - b;
		x2 += shift;
		if(x2 < 0){//w przeciwnym wypadku nic sie nie dzieje
			val -= x2;
		}
		q.push(-shift);
		q.push(-shift);
	}
	//cout<<q.top() + shift<<" "<<val<<"\n\n";
	//obliczamy roznice miedzy 0 a tam gdzie znamy val
	long long diff = 0;
	long long slope = -1;
	long long x = q.top()+shift;
	if(x > 0){
		diff = x;
	}else{
		while(x < 0){
			q.pop();
			slope++;
			long long newX = min(q.top()+shift, 0ll);
			diff += slope * (newX - x);
			x = newX;
		}
	}
	cout<<(val + diff);
}

Compilation message

bulves.cpp: In function 'int main()':
bulves.cpp:13:13: warning: unused variable 'x1' [-Wunused-variable]
   13 |   long long x1 = q.top(); q.pop(); long long x2 = q.top();//pochodna na x1, x2 0 wiec x1 niepotrzebne
      |             ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 33 ms 1700 KB Output is correct
5 Correct 70 ms 2968 KB Output is correct
6 Correct 248 ms 5184 KB Output is correct
7 Correct 403 ms 8872 KB Output is correct
8 Incorrect 387 ms 8852 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 33 ms 1700 KB Output is correct
5 Correct 70 ms 2968 KB Output is correct
6 Correct 248 ms 5184 KB Output is correct
7 Correct 403 ms 8872 KB Output is correct
8 Incorrect 387 ms 8852 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 332 KB Output is correct
13 Correct 5 ms 332 KB Output is correct
14 Correct 3 ms 332 KB Output is correct
15 Correct 3 ms 332 KB Output is correct
16 Correct 3 ms 332 KB Output is correct
17 Correct 2 ms 332 KB Output is correct
18 Correct 3 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 2 ms 332 KB Output is correct
3 Correct 3 ms 376 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 2 ms 332 KB Output is correct
9 Correct 2 ms 332 KB Output is correct
10 Correct 2 ms 332 KB Output is correct
11 Correct 33 ms 1700 KB Output is correct
12 Correct 70 ms 2968 KB Output is correct
13 Correct 248 ms 5184 KB Output is correct
14 Correct 403 ms 8872 KB Output is correct
15 Incorrect 387 ms 8852 KB Output isn't correct
16 Halted 0 ms 0 KB -