237442026-01-28 17:51:15algoproBányász RPG (40 pont)cpp17Wrong answer 36/4064ms932 KiB
// UUID: 2dc5d497-c2aa-4857-a420-4da01ce60eb9
#include <bits/stdc++.h>
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.rbegin(), l.rend());

    int xp = 0, t = 0;
    int i = 0, j = n-1;
    //cout << "i" << " " << "j" << " " << "x" << " " << "jf" << " " << "is" << " " << "t" << "\n";
    while (i <= j) {
        //cout << i << " " << j << " " << xp << " " << l[j].first << "  " << l[i].second << "  " << t << " ";
        if (xp >= l[j].first) {
            //cout << 1 << "\n";
            xp += l[j].second;
            t += l[j].second;
            j--;
        }
        else if (xp + l[i].second > l[j].first) {
            //cout << 2 << "\n";
            t += 2 * (l[j].first - xp);
            l[i].second -= l[j].first - xp;
            xp = l[j].first;

            xp += l[j].second;
            t += l[j].second;
            j--;
        }
        else {
            xp += l[i].second;
            //cout << 3 << "\n";
            t += 2 * (l[i].second);
            i++;
        }
    }

    cout << t;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/01ms508 KiB
2Accepted0/013ms316 KiB
3Accepted2/21ms508 KiB
4Accepted2/22ms316 KiB
5Accepted2/29ms344 KiB
6Accepted2/221ms652 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms508 KiB
9Accepted3/31ms508 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms368 KiB
12Accepted3/31ms384 KiB
13Accepted4/42ms316 KiB
14Accepted4/41ms316 KiB
15Wrong answer0/237ms808 KiB
16Accepted2/250ms932 KiB
17Wrong answer0/241ms836 KiB
18Accepted2/264ms932 KiB