185172025-10-25 15:44:59Firesloth28Bányász RPG (40 pont)cpp17Időlimit túllépés 28/40400ms2084 KiB
#include <bits/stdc++.h>
using namespace std;

bool comp(pair<int, int> a, pair<int, int> b) {
    return a.first < b.first;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

	int n;
    pair<int, int> materials[100001];

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> materials[i].first;
    }
    for (int i = 0; i < n; i++) {
        cin >> materials[i].second;
    }
    
    sort(materials, materials+n, comp);

    int i = 0;
    int j = n - 1;
    int xp = 0;
    int time = 0;

    while (i < j || materials[i].second) {
        if (xp >= materials[i].first) {
            time++;
            if (--(materials[i].second) == 0) {
                i++;
            }
        }
        else {
            time += 2;
            if (--(materials[j].second) == 0) {
                j--;
            }
        }
        xp++;
    }

    cout << time;

}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base28/40
1Elfogadva0/02ms1080 KiB
2Időlimit túllépés0/0386ms1332 KiB
3Elfogadva2/22ms1080 KiB
4Elfogadva2/23ms1076 KiB
5Időlimit túllépés0/2381ms1516 KiB
6Időlimit túllépés0/2381ms1332 KiB
7Elfogadva2/27ms1364 KiB
8Elfogadva2/2201ms1076 KiB
9Elfogadva3/32ms1076 KiB
10Elfogadva3/32ms1076 KiB
11Elfogadva3/32ms1268 KiB
12Elfogadva3/37ms1076 KiB
13Elfogadva4/432ms1076 KiB
14Elfogadva4/418ms1076 KiB
15Időlimit túllépés0/2381ms1588 KiB
16Időlimit túllépés0/2400ms1732 KiB
17Időlimit túllépés0/2398ms1588 KiB
18Időlimit túllépés0/2400ms2084 KiB