240132026-02-03 17:41:37algoproBányász RPG (40 pont)cpp17Time limit exceeded 36/40400ms1076 KiB
// UUID: fc573232-4384-422b-b4ef-76219f6a5637
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main() {
	ios::sync_with_stdio(false);
    cin.tie(0);

    int n; cin >>n;

    vector<pair<int, int>>anyag(n);

    for (int i = 0; i < n; i++){
        cin >>anyag[i].first;
    }
    for (int i = 0; i < n; i++){
        cin >>anyag[i].second;
    }

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

    int tp = 0;
    ll ido = 0;

    int b = 0, j = n-1; 
    while (b <= j){
        if (tp >= anyag[b].first){
            ido+=anyag[b].second;
            tp+=anyag[b].second;
            anyag[b].second = 0;
            b++;
        }
        else{
            anyag[j].second--;
            ido += 2;
            tp++;
            if (anyag[j].second == 0) j--;
        }
        

        //cout <<ido<<'\n';
    }

    cout << ido;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/01ms316 KiB
2Accepted0/06ms316 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms320 KiB
5Accepted2/24ms316 KiB
6Accepted2/210ms564 KiB
7Accepted2/22ms316 KiB
8Accepted2/23ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms428 KiB
13Accepted4/41ms500 KiB
14Accepted4/41ms316 KiB
15Time limit exceeded0/2398ms820 KiB
16Accepted2/224ms820 KiB
17Time limit exceeded0/2400ms696 KiB
18Accepted2/230ms1076 KiB