94142024-02-21 14:11:06AGergoBányász RPG (40 pont)cpp17Hibás válasz 32/4020ms4828 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;
    }
    cout << time;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base32/40
1Elfogadva0/03ms2800 KiB
2Elfogadva0/07ms2948 KiB
3Elfogadva2/23ms2964 KiB
4Elfogadva2/23ms3032 KiB
5Elfogadva2/26ms3160 KiB
6Elfogadva2/28ms3436 KiB
7Elfogadva2/24ms3796 KiB
8Elfogadva2/24ms3664 KiB
9Elfogadva3/33ms3600 KiB
10Elfogadva3/33ms3728 KiB
11Elfogadva3/33ms3940 KiB
12Elfogadva3/33ms4016 KiB
13Elfogadva4/43ms4092 KiB
14Elfogadva4/43ms4228 KiB
15Hibás válasz0/214ms4424 KiB
16Hibás válasz0/217ms4704 KiB
17Hibás válasz0/214ms4780 KiB
18Hibás válasz0/220ms4828 KiB