237452026-01-28 17:51:42algoproBányász RPG (40 pont)cpp17Wrong answer 36/4064ms1076 KiB
// UUID: 83a8a36f-5d4e-4640-8d45-2199a2f96cc2
#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/01ms316 KiB
2Accepted0/012ms524 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/210ms316 KiB
6Accepted2/221ms748 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms508 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms500 KiB
13Accepted4/41ms404 KiB
14Accepted4/41ms416 KiB
15Wrong answer0/237ms564 KiB
16Accepted2/250ms1052 KiB
17Wrong answer0/241ms836 KiB
18Accepted2/264ms1076 KiB