Submission #1229922

#TimeUsernameProblemLanguageResultExecution timeMemory
1229922gry3125Bikeparking (EGOI24_bikeparking)C++20
25 / 100
83 ms4936 KiB
#include <bits/stdc++.h>
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define ll long long int
using namespace std;

int main() {

    ll n, r = 0; cin >> n;
    vector<ll> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i];
    for (int i = 0; i < n; i++) cin >> y[i];
    
    ll cur = n-1;
    for (int i = n-1; i >= 0; i--) {
    	if (cur < 0) continue;
    	while (y[i] > 0) {
    		while ((cur >= 0) && (cur >= i || x[cur] == 0)) cur--;
    		if (cur < 0) break;
    		if (y[i] <= x[cur]) {
    			x[cur] -= y[i];
    			r += y[i]; 
    			y[i] = 0;
    		} else {
    			y[i] -= x[cur];
    			r += x[cur];
    			x[cur] = 0;
    		}
    	}
    }
    ll c = 0;
    for (int i = n-1; i >= 0; i--) {
    	if (c == n) continue;
    	while (y[i] > 0) {
    		while (c < n && x[c] == 0) c++;
    		if (c == n) break;
    		if (y[i] <= x[c]) {
    			if (i < c) r -= y[i];
    			if (i > c) r += y[i];
    			x[c] -= y[i];
    			y[i] = 0;
    		} else {
    			if (i < c) r -= x[c];
    			if (i > c) r += x[c];
    			y[i] -= x[c];
    			x[c] = 0;
    		}
    	}
    }

    cout << r;
    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...