94152024-02-21 14:13:13AGergoBányász RPG (40 pont)cpp17Hibás válasz 32/4021ms4944 KiB
#include <bits/stdc++.h>

using namespace std;

int main()
{
    iostream::sync_with_stdio(0);
    cin.tie(0);


    int n;
    cin >> n;
    vector<int> be(n);
    vector<int> req(100000,0);

    for(int i = 0; i < n; i++)
    {
        cin >> be[i];
    }
    int t;
    for(int i = 0; i < n; i++)
    {
        cin >> t;
        req[be[i]] += t;
    }

    int curExp = 0;
    long long time = 0;

    int l=0; //-> at lowest requirement place
    int h=99999; // highest requirement place



    while(l != h)
    {
        while(req[l]==0)
        {
            l++;
            //cout << l <<"l\n";
        }
        while(req[h]==0)
        {
            h--;
            //cout << h <<"h\n";
        }
        if(curExp >= l)
        {
            //cout << "a\n";
            //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n";
            curExp += req[l];
            time += req[l];
            req[l] = 0;
            //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n----------\n";
        }
        else
        {
            if(curExp + req[h] >= l)
            {
                //cout << "b\n";
                //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n";
                time+=2*(l-curExp);
                req[h]-= l-curExp;
                curExp += l-curExp;
                //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n----------\n";
            }
            else //curExp + x lepés = l -> x-et keressük
            {
                //cout << "c\n";
                //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n";
                curExp += req[h];
                time += 2*req[h];
                req[h] = 0;
                //cout << curExp << "-" << time << " " << l << " " << req[l] << ":" << h << " " << req[h] << "\n----------\n";
            }
        }
    }
    if(curExp>=l)
    {
        curExp += req[l];
        time += req[l];
        req[l] = 0;
    }
    else if(curExp + req[h] < l)
    {
        curExp += req[h];
        time += 2*req[h];
        req[h] = 0;
    }
    else
    {
        time+=2*(l-curExp);
        curExp += l-curExp;
        req[h]-=l-curExp;
        time+=req[h];
    }
    cout << time;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base32/40
1Elfogadva0/03ms2520 KiB
2Elfogadva0/07ms2764 KiB
3Elfogadva2/23ms2848 KiB
4Elfogadva2/23ms3188 KiB
5Elfogadva2/26ms3148 KiB
6Elfogadva2/28ms3528 KiB
7Elfogadva2/24ms3604 KiB
8Elfogadva2/24ms3792 KiB
9Elfogadva3/33ms3744 KiB
10Elfogadva3/33ms3868 KiB
11Elfogadva3/33ms3956 KiB
12Elfogadva3/33ms4024 KiB
13Elfogadva4/43ms3956 KiB
14Elfogadva4/43ms4028 KiB
15Hibás válasz0/214ms4156 KiB
16Hibás válasz0/217ms4548 KiB
17Hibás válasz0/214ms4604 KiB
18Hibás válasz0/221ms4944 KiB