80102024-01-12 10:14:38almadavBányász RPG (40 pont)cpp17Time limit exceeded 28/40400ms3424 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<cv)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/03ms1828 KiB
2Time limit exceeded0/0400ms1428 KiB
3Accepted2/23ms2452 KiB
4Accepted2/24ms2432 KiB
5Time limit exceeded0/2400ms2004 KiB
6Time limit exceeded0/2361ms2392 KiB
7Accepted2/28ms3200 KiB
8Accepted2/2228ms3152 KiB
9Accepted3/33ms3160 KiB
10Accepted3/33ms3164 KiB
11Accepted3/33ms3268 KiB
12Accepted3/38ms3300 KiB
13Accepted4/437ms3320 KiB
14Accepted4/421ms3424 KiB
15Time limit exceeded0/2400ms3180 KiB
16Time limit exceeded0/2349ms3204 KiB
17Time limit exceeded0/2367ms3156 KiB
18Time limit exceeded0/2381ms3388 KiB