94142024-02-21 14:11:06AGergoBányász RPG (40 pont)cpp17Wrong answer 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;
}
SubtaskSumTestVerdictTimeMemory
base32/40
1Accepted0/03ms2800 KiB
2Accepted0/07ms2948 KiB
3Accepted2/23ms2964 KiB
4Accepted2/23ms3032 KiB
5Accepted2/26ms3160 KiB
6Accepted2/28ms3436 KiB
7Accepted2/24ms3796 KiB
8Accepted2/24ms3664 KiB
9Accepted3/33ms3600 KiB
10Accepted3/33ms3728 KiB
11Accepted3/33ms3940 KiB
12Accepted3/33ms4016 KiB
13Accepted4/43ms4092 KiB
14Accepted4/43ms4228 KiB
15Wrong answer0/214ms4424 KiB
16Wrong answer0/217ms4704 KiB
17Wrong answer0/214ms4780 KiB
18Wrong answer0/220ms4828 KiB