201372026-01-02 20:23:29szabelrBányász RPG (40 pont)cpp17Wrong answer 0/4027ms1808 KiB
// Bányász RPG.cpp : This file contains the 'main' function. Program execution begins and ends there.
//

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    vector<pair<int, int>> anyag(n);
    for (int i = 0; i < n; i++)
    {
        cin >> anyag[i].first;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> anyag[i].second;
    }
    sort(anyag.begin(), anyag.end(),[](auto s1, auto s2){
        return s1.second < s2.second;
    });
    int i = 0;
    int j = n-1;
    long long ido = 0;
    long long exp = 0;
    while (i <= j)
    {
        if ( exp >= anyag[i].second)
        {
            exp += anyag[i].first;
            ido += anyag[i].first;
                i++;
        }
        else {
            long long kell = anyag[i].second - exp;
            if (kell >= anyag[j].first)
            {
                exp += anyag[j].first;
                ido += 2 * anyag[j].first;
                j--;
            }
            else
            {
                exp += kell;
                ido += 2 * kell;
                anyag[j].first -= kell;
            }
        }
        
    }
    cout << ido;
}

// Run program: Ctrl + F5 or Debug > Start Without Debugging menu
// Debug program: F5 or Debug > Start Debugging menu

// Tips for Getting Started: 
//   1. Use the Solution Explorer window to add/manage files
//   2. Use the Team Explorer window to connect to source control
//   3. Use the Output window to see build output and other messages
//   4. Use the Error List window to view errors
//   5. Go to Project > Add New Item to create new code files, or Project > Add Existing Item to add existing code files to the project
//   6. In the future, to open this project again, go to File > Open > Project and select the .sln file
SubtaskSumTestVerdictTimeMemory
base0/40
1Wrong answer0/01ms316 KiB
2Wrong answer0/06ms884 KiB
3Wrong answer0/21ms316 KiB
4Wrong answer0/21ms424 KiB
5Wrong answer0/24ms568 KiB
6Wrong answer0/29ms820 KiB
7Wrong answer0/22ms672 KiB
8Wrong answer0/22ms316 KiB
9Wrong answer0/31ms316 KiB
10Wrong answer0/31ms500 KiB
11Wrong answer0/31ms420 KiB
12Wrong answer0/31ms508 KiB
13Wrong answer0/41ms508 KiB
14Wrong answer0/41ms508 KiB
15Wrong answer0/216ms820 KiB
16Wrong answer0/219ms820 KiB
17Wrong answer0/217ms820 KiB
18Wrong answer0/227ms1808 KiB