237492026-01-28 18:19:16algoproBányász RPG (40 pont)cpp17Wrong answer 36/4067ms1096 KiB
// UUID: df282961-b298-443a-a936-4e9ae8a2ef3e
#include <bits/stdc++.h>
#include <csetjmp>
using namespace std;

int main() {
	int n; cin >> n;
    vector<pair<int, int>> l(n);
    for (int i = 0; i < n; i++) {
        cin >> l[i].first;
    }
    for (int i = 0; i < n; i++) {
        cin >> l[i].second;
    }

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

    int xp = 0, t = 0;
    int i = 0, j = n-1;
    while (i <= j) {
        if (xp >= l[i].first) {
            xp += l[i].second;
            t += l[i].second;
            i++;
        } else {
            int kell = l[i].first - xp;
            int vesz = min(kell, l[j].second);

            t += 2 * vesz;
            xp += vesz;
            l[j].second -= vesz;

            if (l[j].second == 0) j--;
        }
    }

    cout << t;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/01ms316 KiB
2Accepted0/013ms316 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/210ms500 KiB
6Accepted2/221ms564 KiB
7Accepted2/23ms344 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms316 KiB
10Accepted3/32ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms400 KiB
13Accepted4/42ms316 KiB
14Accepted4/41ms316 KiB
15Wrong answer0/239ms564 KiB
16Accepted2/250ms820 KiB
17Wrong answer0/243ms820 KiB
18Accepted2/267ms1096 KiB