Submission #1191887

#TimeUsernameProblemLanguageResultExecution timeMemory
1191887oolimryBikeparking (EGOI24_bikeparking)C++20
100 / 100
28 ms9436 KiB
#include <bits/stdc++.h>
using namespace std;
#define sz(x) (int) (x).size()
#define all(x) (x).begin(), (x).end()
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define showlist(x) cerr << #x << " is "; for(auto p : x) cerr << p << " "; cerr << endl;
#define int long long
typedef pair<int,int> ii;

int spots[300005];
int ppl[300005];

signed main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	int n; cin >> n;
	for(int i = 0;i < n;i++) cin >> spots[i];
	for(int i = 0;i < n;i++) cin >> ppl[i];
	
	int good = 0;
	
	vector<int> S;
	for(int i = 0;i < n;i++){
		while(not S.empty()){
			if(ppl[i] == 0) break;
			
			int j = S.back(); 
			
			if(spots[j] == 0){
				S.pop_back();
				continue;
			}
			
			int taken = min(ppl[i], spots[j]);
			good += taken;
			
			spots[j] -= taken;
			ppl[i] -= taken;
		}
		
		S.push_back(i);
	}
		
	int bad = 0;
	/// settle neutral
	for(int i = 0;i < n;i++){
		int taken = min(spots[i], ppl[i]);
		spots[i] -= taken;
		ppl[i] -= taken;
		
		bad += ppl[i];
	}
	
	cout << good-bad;
}


#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...