91632024-02-16 17:30:46UVinceBányász RPG (40 pont)cpp17Accepted 40/4032ms6140 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin >> n;
    vector<pair<ll, ll>> v(n);
    ll sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].first;
    }
    for (int i = 0; i < n; i++)
    {
        cin >> v[i].second;
        sum += v[i].second;
    }
    sort(v.begin(), v.end());
    ll l = 0, r = n - 1, tap = 0, t = 0;
    while (tap < sum)
    {
        if (tap >= v[l].first)
        {
            t += v[l].second;
            tap += v[l].second;
            l++;
        }
        else
        {
            while (v[l].first > tap)
            {
                int add = min(v[r].second, v[l].first - tap);
                tap += add;
                v[r].second -= add;
                t += add * 2;
                if (v[r].second == 0)
                    r--;
            }
        }
    }
    cout << t;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1824 KiB
2Accepted0/08ms2316 KiB
3Accepted2/23ms2236 KiB
4Accepted2/23ms2344 KiB
5Accepted2/27ms2848 KiB
6Accepted2/213ms3728 KiB
7Accepted2/24ms3084 KiB
8Accepted2/24ms3344 KiB
9Accepted3/33ms3400 KiB
10Accepted3/32ms3388 KiB
11Accepted3/32ms3268 KiB
12Accepted3/33ms3276 KiB
13Accepted4/43ms3548 KiB
14Accepted4/43ms3488 KiB
15Accepted2/219ms4824 KiB
16Accepted2/226ms5496 KiB
17Accepted2/221ms5036 KiB
18Accepted2/232ms6140 KiB