제출 #1189320

#제출 시각아이디문제언어결과실행 시간메모리
1189320NomioBikeparking (EGOI24_bikeparking)C++20
25 / 100
27 ms2632 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n), b(n);
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	for(int i = 0; i < n; i++) {
		cin >> b[i];
	}
	ll ans = 0;
	int x = n - 1;
	for(int j = n - 1; j >= 1; j--) {
		x = min(j, x);
		while(x - 1 >= 0 && b[j] > 0) {
			x--;
			if(a[x] >= b[j]) {
				ans += b[j];
				a[x] -= b[j];
				b[j] = 0;
			} else {
				ans += a[x];
				b[j] -= a[x];
				a[x] = 0;
			}
		}
	}
	x = 0;
	for(int i = 0; i < n; i++) {
		b[i] -= a[i];
		while(x + 1 < n && b[i] > 0) {
			x++;
			if(a[x] >= b[i]) {
				ans -= b[i];
				a[x] -= b[i];
				b[i] = 0;
			} else {
				ans -= a[x];
				b[i] -= a[x];
				a[x] = 0;
			}
		}
	}
	cout << ans << '\n';
	return 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...