152502025-02-17 17:42:19szjBányász RPG (40 pont)cpp17Wrong answer 36/4064ms1084 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()
{
    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
base36/40
1Accepted0/01ms316 KiB
2Accepted0/012ms496 KiB
3Accepted2/21ms316 KiB
4Accepted2/21ms316 KiB
5Accepted2/28ms316 KiB
6Accepted2/218ms640 KiB
7Accepted2/23ms316 KiB
8Accepted2/24ms316 KiB
9Accepted3/31ms500 KiB
10Accepted3/31ms316 KiB
11Accepted3/31ms548 KiB
12Accepted3/31ms316 KiB
13Accepted4/41ms316 KiB
14Accepted4/41ms316 KiB
15Wrong answer0/237ms784 KiB
16Accepted2/248ms856 KiB
17Wrong answer0/239ms780 KiB
18Accepted2/264ms1084 KiB