94182024-02-21 14:29:53AblablablaBányász RPG (40 pont)cpp17Accepted 40/4071ms6440 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<ll, ll> pii;

int main()
{
    ll n;
    cin >> n;

    /*vector<ll> minimum(n);
    for(ll &x : minimum){
        cin >> x;
    }

    vector<ll> muszaj(n);
    for(ll &x : muszaj){
        cin >> x;
    }*/

    vector<pii> anyagok(n);
    for(ll i = 0; i < n; i++){
        cin >> anyagok[i].first;
    }

    for(ll i = 0; i < n; i++){
        cin >> anyagok[i].second;
    }

    sort(anyagok.begin(), anyagok.end());

    ll valasz = 0;
    ll mar = 0;
    ll bal = 0, jobb = n - 1;

    while(bal <= jobb){
        while(bal <= jobb && anyagok[bal].first > mar){
            //cout << bal << " " << jobb << " : " << mar << "\n";
            if(anyagok[bal].first <= mar + anyagok[jobb].second){
                valasz += (anyagok[bal].first - mar) * 2;
                //cout << "0 " << (anyagok[bal].first - mar) * 2 << "\n";
                anyagok[jobb].second -= (anyagok[bal].first - mar);
                mar += anyagok[bal].first - mar;
            } else{
                mar += anyagok[jobb].second;
                valasz += anyagok[jobb].second * 2;
                //cout << "1 " << anyagok[jobb].second * 2 << "\n";
                anyagok[jobb].second = 0;
                jobb--;
            }
        }


        valasz += anyagok[bal].second;
        mar += anyagok[bal].second;
        //cout << anyagok[bal].second << "\n";
        anyagok[bal].second = 0;
        bal++;
    }

    cout << valasz << "\n";
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1812 KiB
2Accepted0/014ms2516 KiB
3Accepted2/23ms2276 KiB
4Accepted2/23ms2376 KiB
5Accepted2/213ms3000 KiB
6Accepted2/225ms3676 KiB
7Accepted2/24ms3236 KiB
8Accepted2/26ms3112 KiB
9Accepted3/33ms3020 KiB
10Accepted3/33ms3200 KiB
11Accepted3/33ms3412 KiB
12Accepted3/33ms3504 KiB
13Accepted4/43ms3624 KiB
14Accepted4/43ms3552 KiB
15Accepted2/241ms5028 KiB
16Accepted2/256ms5904 KiB
17Accepted2/246ms5476 KiB
18Accepted2/271ms6440 KiB