80272024-01-12 10:50:54almadavBányász RPG (40 pont)cpp17Runtime error 19/4032ms6288 KiB
#include <bits/stdc++.h>

using namespace std;

struct mineral{
long long needed;
long long lvl;
};

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

int main()
{
    cin.tie(0);
    long long time =0;
    iostream::sync_with_stdio(0);
    long long 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;
    long long cv = 0;
    long long currlvl=0;
    long long dif;
    long long last = n-1;
    while(cv < n)
    {
        dif = items[last].lvl - currlvl;
        if(dif<=0)
        {
            time += items[last].needed;
            currlvl += items[last].needed;
            items[last].needed=0;
            last--;
        }
        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
base19/40
1Accepted0/03ms1824 KiB
2Runtime error0/08ms2664 KiB
3Accepted2/23ms2316 KiB
4Wrong answer0/23ms2624 KiB
5Runtime error0/26ms3152 KiB
6Runtime error0/29ms3648 KiB
7Accepted2/24ms3088 KiB
8Accepted2/24ms3204 KiB
9Accepted3/33ms2904 KiB
10Accepted3/33ms2904 KiB
11Accepted3/33ms3020 KiB
12Wrong answer0/33ms2964 KiB
13Accepted4/43ms3100 KiB
14Wrong answer0/43ms3284 KiB
15Runtime error0/219ms4800 KiB
16Runtime error0/226ms5472 KiB
17Runtime error0/220ms5352 KiB
18Runtime error0/232ms6288 KiB