152512025-02-17 17:44:17szjBányász RPG (40 pont)cpp17Accepted 40/4064ms1072 KiB
#include <iostream>
#include <algorithm>
using namespace std;
struct anyag
{
    int xp, m;
};
bool f(anyag a, anyag b)
{
    return a.xp < b.xp;
}
int main()
{
    long long int n, i, j, pxp=0, ido=0;
    cin >> n;
    anyag t[n];
    for(i=0; i<n; i++)cin >> t[i].xp;
    for(i=0; i<n; i++)cin >> t[i].m;
    sort(t, t+n, f);
    i=n-1;
    j=0;
    while(i>=j)
    {
        if(t[j].xp<=pxp)
        {
            pxp+=t[j].m;
            ido+=t[j].m;
            t[j].m = 0;
            j++;
        }
        else if(t[j].xp-pxp<t[i].m)
        {
            t[i].m-=(t[j].xp-pxp);
            ido+=2*(t[j].xp-pxp);
            pxp+=(t[j].xp-pxp);
        }
        else if(t[j].xp-pxp>t[i].m)
        {
            pxp+=t[i].m;
            ido+=2*t[i].m;
            t[i].m = 0;
            i--;
        }
    }
    cout << ido;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/01ms508 KiB
2Accepted0/012ms316 KiB
3Accepted2/21ms508 KiB
4Accepted2/21ms316 KiB
5Accepted2/29ms496 KiB
6Accepted2/218ms544 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms500 KiB
10Accepted3/31ms500 KiB
11Accepted3/31ms316 KiB
12Accepted3/31ms316 KiB
13Accepted4/42ms316 KiB
14Accepted4/41ms508 KiB
15Accepted2/237ms780 KiB
16Accepted2/250ms916 KiB
17Accepted2/241ms820 KiB
18Accepted2/264ms1072 KiB