185172025-10-25 15:44:59Firesloth28Bányász RPG (40 pont)cpp17Time limit exceeded 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;

}
SubtaskSumTestVerdictTimeMemory
base28/40
1Accepted0/02ms1080 KiB
2Time limit exceeded0/0386ms1332 KiB
3Accepted2/22ms1080 KiB
4Accepted2/23ms1076 KiB
5Time limit exceeded0/2381ms1516 KiB
6Time limit exceeded0/2381ms1332 KiB
7Accepted2/27ms1364 KiB
8Accepted2/2201ms1076 KiB
9Accepted3/32ms1076 KiB
10Accepted3/32ms1076 KiB
11Accepted3/32ms1268 KiB
12Accepted3/37ms1076 KiB
13Accepted4/432ms1076 KiB
14Accepted4/418ms1076 KiB
15Time limit exceeded0/2381ms1588 KiB
16Time limit exceeded0/2400ms1732 KiB
17Time limit exceeded0/2398ms1588 KiB
18Time limit exceeded0/2400ms2084 KiB