72022024-01-03 13:02:50MagyarKendeSZLGBányász RPG (40 pont)cpp17Accepted 40/4035ms5460 KiB
#include <bits/stdc++.h>

#define speed cin.tie(0); ios::sync_with_stdio(0)
#define cinv(v) for (auto& e : v) cin >> e;
#define all(v) v.begin(), v.end()
#define has(s, e) s.count(e)

using namespace std;
using ll = long long;
using point = array<int, 2>;

int main() {
    speed;

    int N;
    cin >> N;
    vector<point> v(N);

    for (int i = 0; i < N; i++) cin >> v[i][0];
    for (int i = 0; i < N; i++) cin >> v[i][1];

    sort(all(v));

    ll t = 0, xp = 0;
    int l = 0, r = N - 1;
    while (l <= r) {
        if (v[l][0] <= xp) {
            // finish the remaining in one sitting (yum)
            t += v[l][1];
            xp += v[l][1];
            v[l] = {0, 0};
            l++;
        } else {
            // if had to finish the inefficient way, this is done (mining be boring aa hell)
            if (--v[r][1] == 0) r--;
            t += 2; // go one by one here, time and xp gain is constant
            xp++;
        }
    }

    cout << t;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/08ms2268 KiB
3Accepted2/23ms2232 KiB
4Accepted2/23ms2456 KiB
5Accepted2/28ms2884 KiB
6Accepted2/214ms3312 KiB
7Accepted2/24ms3172 KiB
8Accepted2/24ms3256 KiB
9Accepted3/33ms3408 KiB
10Accepted3/33ms3508 KiB
11Accepted3/33ms3988 KiB
12Accepted3/33ms3960 KiB
13Accepted4/43ms3976 KiB
14Accepted4/43ms4124 KiB
15Accepted2/221ms5028 KiB
16Accepted2/228ms5116 KiB
17Accepted2/223ms4940 KiB
18Accepted2/235ms5460 KiB