240172026-02-03 17:57:51algoproBányász RPG (40 pont)cpp17Accepted 40/4030ms1076 KiB
// UUID: 4f93c601-fe0c-402b-bf1b-1d1ad81f5ea2
#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());

    ll tp = 0;
    ll ido = 0;

    int cnt = 0;

    int b = 0, j = n-1;
    while (b <= j){
        if(cnt > 200001)
        cnt++;
        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;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms316 KiB
2Accepted0/06ms544 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/24ms316 KiB
6Accepted2/212ms564 KiB
7Accepted2/22ms316 KiB
8Accepted2/22ms316 KiB
9Accepted3/32ms500 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms388 KiB
14Accepted4/41ms316 KiB
15Accepted2/217ms824 KiB
16Accepted2/224ms792 KiB
17Accepted2/219ms748 KiB
18Accepted2/230ms1076 KiB