Submission #1207598

#TimeUsernameProblemLanguageResultExecution timeMemory
1207598trimkusBikeparking (EGOI24_bikeparking)C++20
0 / 100
51 ms4796 KiB
#include <bits/stdc++.h>
using namespace std;



int main() {
	//~ ifstream cin("input.txt");
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	int cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	for (int i = 0; i < n; ++i) {
		cin >> b[i];
		cnt += b[i];
	}
	//~ cout << cnt << endl;
	vector<int> avl;
	int res = 0;
	int left = 0;
	for (int i = 0; i < n; ++i) {
		avl.push_back(i);
		while (left > 0 && avl.size()) {
			int j = avl.back();
			int take = min(a[j], left);
			res -= take;
			left -= take;
			a[j] -= take;
			if (a[j] == 0) {
				avl.pop_back();
			}
		}
		while (avl.size() && b[i] > 0) {
			int j = avl.back();
			int take = min(a[j], b[i]);
			res += take;
			b[i] -= take;
			a[j] -= take;
			if (a[j] == 0) {
				avl.pop_back();
			}
		}
		int take = min(b[i], a[i]);
		b[i] -= take;
		a[i] -= take;
		left += b[i];
		
	}
	//~ for (int i = n - 1; i >= 0; --i) {
		//~ int take = min(b[i], a[i]);
		//~ b[i] -= take;
		//~ res -= b[i];
	//~ }
	cout << res << "\n";
}
/*
10
0 0 0 0 0 0 0 1 1 1
1 0 0 1 0 1 0 0 0 0
*/
#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...