79772024-01-12 09:36:25almadavBányász RPG (40 pont)cpp17Time limit exceeded 0/40374ms3728 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/0345ms1804 KiB
2Time limit exceeded0/0372ms1528 KiB
3Runtime error0/23ms2440 KiB
4Runtime error0/24ms2416 KiB
5Time limit exceeded0/2354ms1920 KiB
6Time limit exceeded0/2374ms2376 KiB
7Runtime error0/28ms2960 KiB
8Time limit exceeded0/2367ms2380 KiB
9Runtime error0/33ms3480 KiB
10Runtime error0/33ms3196 KiB
11Time limit exceeded0/3349ms2360 KiB
12Time limit exceeded0/3356ms2540 KiB
13Time limit exceeded0/4361ms3304 KiB
14Time limit exceeded0/4356ms3288 KiB
15Time limit exceeded0/2368ms3304 KiB
16Time limit exceeded0/2358ms3624 KiB
17Time limit exceeded0/2372ms3316 KiB
18Time limit exceeded0/2361ms3728 KiB