89962024-02-11 12:26:00csdavidBányász RPG (40 pont)cpp17Time limit exceeded 36/40363ms8980 KiB
#include <iostream>
#include <algorithm>
//#include <fstream>
using namespace std;

struct alapanyag{
    int xp;
    int m;
};

bool alma(alapanyag x, alapanyag y){
    return x.xp<y.xp;
}

int main()
{
    //ifstream f("be2.txt");
    int n, e=0, xp=0;
    cin >> n;
    alapanyag a[n];
    for(int i=0; i<n; i++){
        cin >> a[i].xp;
    }
    for(int i=0; i<n; i++){
        cin >> a[i].m;
    }
    sort(a, a+n, alma);
    /*for(int i=0; i<n; i++){
        cout << a[i].xp;
    }*/
    int i=0;
    int j=n-1;
    while(true){
        while(xp<a[i].xp){
            if(a[j].m>0){
                xp++;
                a[j].m--;
                e=e+2;
            }
            else if(j>i){
                j--;
            }
            else{
                e = e + a[j].m*2;
                cout << e;
                return 0;
            }
        }
        e = e + a[i].m;
        xp=xp + a[i].m;
        a[i].m=0;
        i++;
        if(i>j){
            cout << e;
            return 0;
        }
    }

    cout << e;
    return 0;
}
SubtaskSumTestVerdictTimeMemory
base36/40
1Accepted0/03ms2024 KiB
2Accepted0/014ms2696 KiB
3Accepted2/23ms2556 KiB
4Accepted2/23ms2780 KiB
5Accepted2/212ms3344 KiB
6Accepted2/220ms4028 KiB
7Accepted2/24ms3848 KiB
8Accepted2/26ms3840 KiB
9Accepted3/33ms3900 KiB
10Accepted3/33ms3940 KiB
11Accepted3/33ms4076 KiB
12Accepted3/33ms4336 KiB
13Accepted4/43ms4448 KiB
14Accepted4/43ms4584 KiB
15Time limit exceeded0/2338ms4760 KiB
16Accepted2/254ms6948 KiB
17Time limit exceeded0/2363ms6220 KiB
18Accepted2/270ms8980 KiB