80222024-01-12 10:36:30almadavBányász RPG (40 pont)cpp17Time limit exceeded 28/40400ms3620 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 dif;
    int last = n-1;
    while(cv < n)
    {
        dif = items[last].lvl - currlvl;
        if(dif<=0)
        {
            if(items[last].needed == 0)
            {
                last--;
            }
            else
            {
                items[last].needed--;
                time+=1;
                //cout << "egyszer"<<endl;
                currlvl++;
            }
            if(last<cv)break;
        }
        else{
        //cout << items[cv].needed <<" " <<dif << endl;
        if(items[cv].needed == 0)
        {
            cv++;
        }
        else
        {
            for(int j=0;j<min(dif,items[cv].needed);j++)
                {
                    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/0400ms1452 KiB
3Accepted2/23ms2292 KiB
4Accepted2/24ms2488 KiB
5Time limit exceeded0/2342ms1764 KiB
6Time limit exceeded0/2349ms2064 KiB
7Accepted2/28ms2828 KiB
8Accepted2/2192ms3148 KiB
9Accepted3/33ms3356 KiB
10Accepted3/33ms3364 KiB
11Accepted3/33ms3456 KiB
12Accepted3/38ms3536 KiB
13Accepted4/432ms3536 KiB
14Accepted4/418ms3620 KiB
15Time limit exceeded0/2400ms3108 KiB
16Time limit exceeded0/2344ms3300 KiB
17Time limit exceeded0/2365ms3244 KiB
18Time limit exceeded0/2367ms3532 KiB