제출 #1350200

#제출 시각아이디문제언어결과실행 시간메모리
1350200efegBikeparking (EGOI24_bikeparking)C++20
25 / 100
18 ms2640 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;
    i64 up = 0,notr = 0;  
    while(i > -1 && j > -1){
        // cout << i << " " << j << '\n'; 
        if (i >= j) i--;
        else {
            int mn = min(x[i],y[j]); 
            up += mn; 
            x[i] -= mn; 
            y[j] -= mn; 
            if (x[i] == 0) i--; 
            if (y[j] == 0) j--; 
        } 
    }

    for (int i = 0; i < n; i++){
        notr += min(x[i],y[i]); 
    }

    // cout << up << " " << notr << endl; 
    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...