48742023-04-05 20:31:01CWMBányász RPG (40 pont)cpp17Accepted 40/4030ms6516 KiB
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>

//upper bound >
//lower bound >=
//int index = (lower_bound(testvec.begin(), testvec.end(), num)-testvec.begin());

using namespace std;
using ll = long long;
#define int ll
int mod = 1000000007;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    int c;
    cin >> c;
    vector<pair<int,int>> exp(c); //expReq, amount
    for (size_t i = 0; i < c; i++)
    {
        int a;
        cin >> a;
        exp[i] = { a,0 };
    }
    for (size_t i = 0; i < c; i++)
    {
        int a;
        cin >> a;
        exp[i] = { exp[i].first,a };
    }
    sort(exp.begin(), exp.end());
    int totalEllapsed = 0;
    int fwindex = 0;
    int bwindex = c - 1;
    int curExp = 0;
    while (true)
    {
        if (bwindex == fwindex) {
            int expneeded = exp[fwindex].first - curExp;
            if (expneeded < 0) expneeded = 0;
            totalEllapsed += 2 * (expneeded);
            curExp = exp[fwindex].first;
            exp[fwindex] = { exp[fwindex].first,exp[fwindex].second - expneeded };
            totalEllapsed += exp[fwindex].second;
            cout << totalEllapsed;
            return 0;
        }
        if (curExp >= exp[fwindex].first) {
            totalEllapsed += exp[fwindex].second;
            curExp += exp[fwindex].second;
            exp[fwindex] = { exp[fwindex].first,0 };
            fwindex++;
        }
        else {
            if (exp[fwindex].first - curExp < exp[bwindex].second) {
                totalEllapsed += 2 * (exp[fwindex].first - curExp);
                exp[bwindex] = { exp[bwindex].first,exp[bwindex].second - (exp[fwindex].first - curExp) };
                curExp = exp[fwindex].first;
            }
            else {
                totalEllapsed += 2 * (exp[bwindex].second);
                curExp += exp[bwindex].second;
                exp[bwindex] = { exp[bwindex].first,0 };
                bwindex--;
            }
        }
    }
    cout << totalEllapsed;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1828 KiB
2Accepted0/07ms2352 KiB
3Accepted2/22ms2136 KiB
4Accepted2/23ms2284 KiB
5Accepted2/26ms2484 KiB
6Accepted2/212ms3256 KiB
7Accepted2/24ms2836 KiB
8Accepted2/24ms3076 KiB
9Accepted3/32ms3016 KiB
10Accepted3/33ms3076 KiB
11Accepted3/33ms3292 KiB
12Accepted3/33ms3380 KiB
13Accepted4/43ms3652 KiB
14Accepted4/43ms3592 KiB
15Accepted2/217ms5180 KiB
16Accepted2/224ms6016 KiB
17Accepted2/219ms5492 KiB
18Accepted2/230ms6516 KiB