94152024-02-21 14:13:13AGergoBányász RPG (40 pont)cpp17Wrong answer 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;
}
SubtaskSumTestVerdictTimeMemory
base32/40
1Accepted0/03ms2520 KiB
2Accepted0/07ms2764 KiB
3Accepted2/23ms2848 KiB
4Accepted2/23ms3188 KiB
5Accepted2/26ms3148 KiB
6Accepted2/28ms3528 KiB
7Accepted2/24ms3604 KiB
8Accepted2/24ms3792 KiB
9Accepted3/33ms3744 KiB
10Accepted3/33ms3868 KiB
11Accepted3/33ms3956 KiB
12Accepted3/33ms4024 KiB
13Accepted4/43ms3956 KiB
14Accepted4/43ms4028 KiB
15Wrong answer0/214ms4156 KiB
16Wrong answer0/217ms4548 KiB
17Wrong answer0/214ms4604 KiB
18Wrong answer0/221ms4944 KiB