Submission #473492

# Submission time Handle Problem Language Result Execution time Memory
473492 2021-09-15T15:27:09 Z Fgdxx Potatoes and fertilizers (LMIO19_bulves) C++17
0 / 100
1 ms 204 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 += abs(x2);
		}
		q.push(-shift);
	}
	//obliczamy roznice miedzy 0 a tam gdzie znamy val
	long long diff = 0;
	long long slope = 0;
	long long x = q.top();
	if(x > 0){
		diff = -x;
	}else{
		while(x < 0){
			q.pop();
			long long newX = min(q.top(), 0);
			diff += slope * (newX - x);
			slope++;
			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
      |             ^~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -