제출 #1350214

#제출 시각아이디문제언어결과실행 시간메모리
1350214efegBikeparking (EGOI24_bikeparking)C++20
100 / 100
26 ms2784 KiB
#include <bits/stdc++.h>
using namespace std;

#define F first
#define S second
#define all(v) v.begin(),v.end()
#define pb push_back

using i64 = long long; 
template<typename T>
using vec = vector<T>; 
using pi = pair<int,int>; 

template<typename T,size_t n>
using arr = array<T,n>; 

int n; 
vec<int> x,y; 

int32_t main(){
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); 
    cin >> n;
    int sum = 0;  
    x.assign(n,0); 
    y.assign(n,0); 
    for (int i = 0; i < n; i++) cin >> x[i]; 
    for (int i = 0; i < n; i++){
        cin >> y[i]; 
        sum += y[i]; 
    } 

    int i = n-1,j = n-1;
    int total = 0,up = 0,notr = 0; 
    for (int i = n-1; i > -1; i--){
        int mn = min(total,x[i]); 
        up += mn; 
        total -= mn; 
        x[i] -= mn; 

        mn = min(notr,x[i]); 
        up += mn; 
        notr -= mn; 
        x[i] -= mn; 

        int mn2 = min(x[i],y[i]); 
        notr += mn2; 
        y[i] -= mn2; 
        total += y[i]; 
    }

    // cout << up << " " << notr << " " << sum << '\n'; 
    cout << 2 * up + notr - sum << '\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...