94682024-02-22 09:25:21csaron71Bányász RPG (40 pont)cpp17Time limit exceeded 36/40400ms7120 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> kell;
    vector<pair<int, int> > kovek;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        kell.push_back(x);
    }
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        kovek.push_back({kell[i], x});
    }
    sort(kovek.begin(), kovek.end());
    deque<pair<int, int> > sor; // szint, hany
    for (auto sz : kovek) {
        sor.push_back(sz);
    }

    int szint=0;
    int ido=0;
    while (sor.size()>0) {
        if (szint>=sor.front().first) {
            szint+=sor.front().second;
            ido+=sor.front().second;
            sor.pop_front();
        }
        else {
            if (sor.back().second==0) {
                sor.pop_back();
            }
            ido+=2;
            sor.back().second--;
            szint++;
        }
        //cout << "\n" << szint << " TIME: " << ido << "\n";
    }

    cout << ido << " \n";
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/03ms1808 KiB
2Accepted0/014ms2636 KiB
3Accepted2/23ms2272 KiB
4Accepted2/23ms2508 KiB
5Accepted2/213ms3084 KiB
6Accepted2/225ms4040 KiB
7Accepted2/24ms3296 KiB
8Accepted2/26ms3260 KiB
9Accepted3/33ms3272 KiB
10Accepted3/33ms3492 KiB
11Accepted3/33ms3576 KiB
12Accepted3/33ms3708 KiB
13Accepted4/43ms3804 KiB
14Accepted4/43ms4072 KiB
15Time limit exceeded0/2400ms4332 KiB
16Accepted2/256ms6592 KiB
17Time limit exceeded0/2370ms4228 KiB
18Accepted2/274ms7120 KiB