Submission #478305

# Submission time Handle Problem Language Result Execution time Memory
478305 2021-10-06T22:06:14 Z Samboor Potatoes and fertilizers (LMIO19_bulves) C++17
100 / 100
199 ms 23236 KB
// Grzegorz Ryn
// V LO Kraków

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define st first
#define nd second
#define FOR(__VAR, __START, __END) for(int __VAR=__START; __VAR<=__END; __VAR++)
#define FORB(__VAR, __START, __END) for(int __VAR=__START; __VAR>=__END; __VAR--)
#define FORK(__VAR, __START, __END, __DIFF) for(int __VAR=__START; __VAR<=END; __VAR+=__DIFF)
#define all(__VAR) (__VAR).begin(), (__VAR).end()
#define rall(__VAR) (__VAR).rbegin(), (__VAR).rend()
#define DEBUG(__VAR) cout << #__VAR << ": " << __VAR << endl;

template<typename __T1, typename __T2>
ostream & operator<<(ostream &out, pair<__T1, __T2> &__VAR) {
	cout << "[" << __VAR.st << ", " << __VAR.nd << "]";
	return out;
}

template<typename __T>
ostream & operator<<(ostream &out, vector<__T> &__VAR) {
	cout << "[";
	FOR(i, 0, (int)__VAR.size()-2)
		cout << __VAR[i] << ", ";
	if(__VAR.size()>0)
		cout << __VAR[__VAR.size()-1];
	cout << "]" << endl;
	
	return out;
}

const int INF=1e9;

void print(priority_queue<ll, vector<ll>, greater<ll>> Q, ll trans) {
	cout << "Q: " << endl;
	while(!Q.empty()) {
		cout << Q.top()-trans << ' ';
		Q.pop();
	}
	cout << endl;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int N;
	cin >> N;
	vector<ll> a(N), b(N);
	for(int i=0; i<N; i++) {
		cin >> a[i] >> b[i];
	}
	
	priority_queue<ll, vector<ll>, greater<ll>> Q;
	for(int i=0; i<N+1; i++) {
		Q.push(0);
	}
	ll trans=0;
	ll result=0;
	for(int i=0; i<N; i++) {
		trans += b[i]-a[i];
		ll st = Q.top();
		result += max(trans-st, 0LL);
		Q.push(trans);
		Q.push(trans);
		Q.pop();
		//cout << result << endl;
		//print(Q, trans);
	}
	
	ll slope=0, prev=-1e16;
	while(!Q.empty()) {
		ll cur=Q.top();
		Q.pop();
		
		result += slope * (cur-prev);
		prev = cur;
		slope++;
		
		if(cur-trans == 0) {
			break;
		}
	}
	
	cout << result << '\n';

	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 16 ms 2508 KB Output is correct
5 Correct 31 ms 4720 KB Output is correct
6 Correct 104 ms 11768 KB Output is correct
7 Correct 136 ms 23224 KB Output is correct
8 Correct 172 ms 21312 KB Output is correct
9 Correct 146 ms 20660 KB Output is correct
10 Correct 115 ms 18368 KB Output is correct
11 Correct 127 ms 18356 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 16 ms 2508 KB Output is correct
5 Correct 31 ms 4720 KB Output is correct
6 Correct 104 ms 11768 KB Output is correct
7 Correct 136 ms 23224 KB Output is correct
8 Correct 172 ms 21312 KB Output is correct
9 Correct 146 ms 20660 KB Output is correct
10 Correct 115 ms 18368 KB Output is correct
11 Correct 127 ms 18356 KB Output is correct
12 Correct 49 ms 6112 KB Output is correct
13 Correct 120 ms 17408 KB Output is correct
14 Correct 159 ms 23160 KB Output is correct
15 Correct 180 ms 21308 KB Output is correct
16 Correct 199 ms 20672 KB Output is correct
17 Correct 100 ms 18412 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 464 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 1 ms 464 KB Output is correct
12 Correct 1 ms 336 KB Output is correct
13 Correct 1 ms 464 KB Output is correct
14 Correct 1 ms 464 KB Output is correct
15 Correct 1 ms 464 KB Output is correct
16 Correct 2 ms 464 KB Output is correct
17 Correct 2 ms 464 KB Output is correct
18 Correct 1 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 460 KB Output is correct
3 Correct 1 ms 460 KB Output is correct
4 Correct 0 ms 204 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 464 KB Output is correct
8 Correct 2 ms 464 KB Output is correct
9 Correct 1 ms 464 KB Output is correct
10 Correct 1 ms 464 KB Output is correct
11 Correct 16 ms 2508 KB Output is correct
12 Correct 31 ms 4720 KB Output is correct
13 Correct 104 ms 11768 KB Output is correct
14 Correct 136 ms 23224 KB Output is correct
15 Correct 172 ms 21312 KB Output is correct
16 Correct 146 ms 20660 KB Output is correct
17 Correct 115 ms 18368 KB Output is correct
18 Correct 127 ms 18356 KB Output is correct
19 Correct 49 ms 6112 KB Output is correct
20 Correct 120 ms 17408 KB Output is correct
21 Correct 159 ms 23160 KB Output is correct
22 Correct 180 ms 21308 KB Output is correct
23 Correct 199 ms 20672 KB Output is correct
24 Correct 100 ms 18412 KB Output is correct
25 Correct 1 ms 336 KB Output is correct
26 Correct 1 ms 464 KB Output is correct
27 Correct 1 ms 464 KB Output is correct
28 Correct 1 ms 464 KB Output is correct
29 Correct 2 ms 464 KB Output is correct
30 Correct 2 ms 464 KB Output is correct
31 Correct 1 ms 464 KB Output is correct
32 Correct 1 ms 464 KB Output is correct
33 Correct 38 ms 6120 KB Output is correct
34 Correct 91 ms 17408 KB Output is correct
35 Correct 160 ms 23232 KB Output is correct
36 Correct 155 ms 20792 KB Output is correct
37 Correct 157 ms 21300 KB Output is correct
38 Correct 152 ms 23236 KB Output is correct
39 Correct 128 ms 19384 KB Output is correct
40 Correct 121 ms 18528 KB Output is correct
41 Correct 102 ms 18364 KB Output is correct
42 Correct 112 ms 18360 KB Output is correct
43 Correct 128 ms 18348 KB Output is correct
44 Correct 101 ms 18364 KB Output is correct
45 Correct 185 ms 23220 KB Output is correct
46 Correct 126 ms 18744 KB Output is correct
47 Correct 98 ms 17408 KB Output is correct