152512025-02-17 17:44:17szjBányász RPG (40 pont)cpp17Elfogadva 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;
}
RészfeladatÖsszpontTesztVerdiktIdőMemória
base40/40
1Elfogadva0/01ms508 KiB
2Elfogadva0/012ms316 KiB
3Elfogadva2/21ms508 KiB
4Elfogadva2/21ms316 KiB
5Elfogadva2/29ms496 KiB
6Elfogadva2/218ms544 KiB
7Elfogadva2/23ms316 KiB
8Elfogadva2/24ms316 KiB
9Elfogadva3/31ms500 KiB
10Elfogadva3/31ms500 KiB
11Elfogadva3/31ms316 KiB
12Elfogadva3/31ms316 KiB
13Elfogadva4/42ms316 KiB
14Elfogadva4/41ms508 KiB
15Elfogadva2/237ms780 KiB
16Elfogadva2/250ms916 KiB
17Elfogadva2/241ms820 KiB
18Elfogadva2/264ms1072 KiB