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

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    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/03ms1700 KiB
2Accepted0/08ms2576 KiB
3Accepted2/23ms2184 KiB
4Accepted2/23ms2204 KiB
5Accepted2/27ms2936 KiB
6Accepted2/214ms3468 KiB
7Accepted2/24ms2776 KiB
8Accepted2/24ms3036 KiB
9Accepted3/33ms2976 KiB
10Accepted3/33ms3188 KiB
11Accepted3/32ms3268 KiB
12Accepted3/33ms3516 KiB
13Accepted4/43ms3784 KiB
14Accepted4/43ms3772 KiB
15Time limit exceeded0/2400ms4180 KiB
16Accepted2/228ms6696 KiB
17Time limit exceeded0/2375ms4196 KiB
18Accepted2/237ms7252 KiB