136122025-01-08 11:24:05EsVagyBányász RPG (40 pont)cpp17Wrong answer 0/4061ms1268 KiB
#include <bits/stdc++.h>

using namespace std;

struct material {
    int xp, needed;

    bool operator<(const material& other) const {
        return this->xp < other.xp;
    }
};

int main()
{
    int n;
    cin >> n;
    vector<material> materials(n);
    for (int i = 0; i < n; i++) {
        cin >> materials[i].xp;
    }
    for (int i = 0; i < n; i++) {
        cin >> materials[i].needed;
    }

    sort(materials.begin(), materials.end());
    int start = 0;
    int end = n - 1;
    int xp = 0;
    int ans = 0;
    while (start <= end) {
        if (xp >= materials[start].xp) {
            xp += materials[start].needed;
            ans += materials[start].needed;
            start++;
        } else {
            int diff = materials[start].xp - xp;
            int sub = min(diff, materials[end].needed);
            xp += sub;
            materials[end].needed -= sub;
            ans += 2 * materials[end].needed;
            if (materials[end].needed == 0) {
                end--;
            }
        }
    }

    cout << ans << endl;

    return 0;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Accepted0/01ms316 KiB
2Wrong answer0/012ms316 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms316 KiB
5Wrong answer0/28ms496 KiB
6Wrong answer0/217ms660 KiB
7Wrong answer0/23ms428 KiB
8Wrong answer0/24ms432 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms316 KiB
11Wrong answer0/31ms384 KiB
12Wrong answer0/31ms404 KiB
13Wrong answer0/41ms316 KiB
14Wrong answer0/41ms508 KiB
15Wrong answer0/235ms796 KiB
16Wrong answer0/246ms820 KiB
17Wrong answer0/239ms840 KiB
18Wrong answer0/261ms1268 KiB