80092024-01-12 10:13:51almadavBányász RPG (40 pont)cpp17Time limit exceeded 28/40400ms3600 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++;
            }
            if(last<0)break;
        }
        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
base28/40
1Accepted0/03ms2008 KiB
2Time limit exceeded0/0400ms1540 KiB
3Accepted2/23ms2276 KiB
4Accepted2/24ms2492 KiB
5Time limit exceeded0/2400ms2568 KiB
6Time limit exceeded0/2352ms2016 KiB
7Accepted2/28ms2644 KiB
8Accepted2/2228ms2696 KiB
9Accepted3/33ms2840 KiB
10Accepted3/33ms2868 KiB
11Accepted3/33ms2996 KiB
12Accepted3/38ms3192 KiB
13Accepted4/437ms3424 KiB
14Accepted4/421ms3408 KiB
15Time limit exceeded0/2349ms3136 KiB
16Time limit exceeded0/2367ms3596 KiB
17Time limit exceeded0/2361ms3348 KiB
18Time limit exceeded0/2365ms3600 KiB