242952026-02-08 12:41:58hunzombiBányász RPG (40 pont)cpp17Elfogadva 40/4067ms1780 KiB
#include <bits/stdc++.h>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<long long, long long>> v(n);

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

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

    long long mined = 0;
    long long res = 0;

    int i=0;

    while (total > 0) {
        long long needed_xp_for_left = max(0LL, v[i].first - mined);
        if (needed_xp_for_left >= total) {
            res += 2 * total;
            mined += total;
            total = 0;
        } else {
            res += 2 * needed_xp_for_left;
            mined += needed_xp_for_left;
            total -= needed_xp_for_left;
            mined += min(total, v[i].second);
            res += min(total, v[i].second);
            total -= min(total, v[i].second);
        }
        i++;
    }

    cout << res << '\n';

    return 0;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/01ms316 KiB
2Elfogadva0/013ms564 KiB
3Elfogadva2/21ms316 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/210ms564 KiB
6Elfogadva2/221ms820 KiB
7Elfogadva2/23ms388 KiB
8Elfogadva2/24ms316 KiB
9Elfogadva3/31ms508 KiB
10Elfogadva3/31ms316 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms500 KiB
13Elfogadva4/41ms316 KiB
14Elfogadva4/41ms316 KiB
15Elfogadva2/239ms1160 KiB
16Elfogadva2/252ms1460 KiB
17Elfogadva2/241ms1264 KiB
18Elfogadva2/267ms1780 KiB