79732024-01-12 09:34:14almadavBányász RPG (40 pont)cpp17Time limit exceeded 0/40377ms7388 KiB
#include <bits/stdc++.h>

using namespace std;

struct mineral{
int needed;
int lvl;
};

bool sortby(mineral a, mineral b)
{
    return a.lvl>b.lvl;
}

int main()
{
    cin.tie(0);
    int time =0;
    iostream::sync_with_stdio(0);
    int n;
    cin >> n;
    vector<mineral> items(n);
    for(int i = 0; i < n; i++)
    {
        cin >> items[i].lvl;
    }
    for(int i = 0; i < n; i++)
    {
        cin >> items[i].needed;
    }
    sort(items.begin(),items.end(),sortby);
    //for(auto x:items)cout << x.lvl <<" " << x.needed <<endl;
    int cv = 0;
    int currlvl=0;
    int last = n-1;
    while(cv < n)
    {
        if(items[last].lvl<=currlvl)
        {
            if(items[last].needed == 0)
            {
                last--;
            }
            else
            {
                items[last].needed--;
                time+=1;
                //cout << "egyszer"<<endl;
                currlvl++;
            }
        }
        else{
        if(items[cv].needed == 0)
        {
            cv++;
        }
        else
        {
            items[cv].needed--;
            time+=2;
            //cout << "ketszer"<<endl;
            currlvl++;
        }}
    }
    //for(auto x:items)cout << x.lvl <<" " << x.needed <<endl;
    cout << time;
}
SubtaskSumTestVerdictTimeMemory
base0/40
1Time limit exceeded0/0361ms1804 KiB
2Time limit exceeded0/0377ms1712 KiB
3Runtime error0/23ms2552 KiB
4Runtime error0/24ms2744 KiB
5Time limit exceeded0/2361ms2648 KiB
6Time limit exceeded0/2354ms3212 KiB
7Runtime error0/28ms3996 KiB
8Time limit exceeded0/2356ms3432 KiB
9Runtime error0/33ms4200 KiB
10Runtime error0/33ms4180 KiB
11Time limit exceeded0/3354ms3388 KiB
12Time limit exceeded0/3337ms3340 KiB
13Time limit exceeded0/4365ms3536 KiB
14Time limit exceeded0/4349ms3528 KiB
15Time limit exceeded0/2368ms4688 KiB
16Time limit exceeded0/2356ms5860 KiB
17Time limit exceeded0/2370ms6324 KiB
18Time limit exceeded0/2345ms7388 KiB