91622024-02-16 17:30:06UVinceBányász RPG (40 pont)cpp17Runtime error 36/4030ms6032 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> 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());
    int 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
base36/40
1Accepted0/03ms1832 KiB
2Accepted0/08ms2560 KiB
3Accepted2/23ms2688 KiB
4Accepted2/23ms2820 KiB
5Accepted2/27ms3156 KiB
6Accepted2/212ms3748 KiB
7Accepted2/24ms3636 KiB
8Accepted2/24ms3908 KiB
9Accepted3/33ms3932 KiB
10Accepted3/33ms3788 KiB
11Accepted3/33ms3792 KiB
12Accepted3/33ms4032 KiB
13Accepted4/43ms4136 KiB
14Accepted4/43ms4140 KiB
15Runtime error0/218ms5532 KiB
16Accepted2/224ms5600 KiB
17Runtime error0/220ms5740 KiB
18Accepted2/230ms6032 KiB