92862024-02-19 19:43:15antiBányász RPG (40 pont)cpp17Wrong answer 29/40381ms6392 KiB
#include <iostream>
#include <algorithm>

using namespace std;

struct alapanyag{
    int l, m;
    int ido = 2;
    bool kesz = false;
};

bool kisebb(alapanyag A1, alapanyag A2){
    return A1.l < A2.l;
}

int main()
{
    int n;
    cin >> n;
    alapanyag A[n];
    for(int i=0; i<n; i++){
        cin >> A[i].l;
    }
    for(int i=0; i<n; i++){
        cin >> A[i].m;
    }
    sort(A, A+n, kisebb);
    /*
    cout << endl;
    for(int i=0; i<n; i++){
        cout << A[i].l << " ";
    }
    cout << endl;
    for(int i=0; i<n; i++){
        cout << A[i].m << " ";
    }
    cout << endl << endl;
    */
    int t=0;

    int h=0, k=n-1;
    int c, xp = 0;
    while(h!=k){
        c = A[h].l;
        while(A[k].m - c < 0){
            c -= A[k].m;
            t += 2 * A[k].m;
            xp = A[k].m;
            k--;
        }
        A[k].m -= c;
        t += 2 * c;
        xp += c;
        while(xp >= A[h].l && h<=k){
            t += A[h].m;
            xp += A[h].m;
            h++;
        }
        h--;
    }
    //cout << xp << endl;
    cout << t << endl;
}

/*
5
2 3 5 6 7
4 2 2 6 5
*/
SubtaskSumTestVerdictTimeMemory
base29/40
1Accepted0/03ms1748 KiB
2Accepted0/014ms2404 KiB
3Accepted2/23ms2124 KiB
4Accepted2/23ms2344 KiB
5Accepted2/210ms3000 KiB
6Accepted2/221ms3748 KiB
7Accepted2/24ms2892 KiB
8Accepted2/26ms2980 KiB
9Wrong answer0/33ms3036 KiB
10Accepted3/33ms3056 KiB
11Accepted3/33ms3188 KiB
12Accepted3/33ms3272 KiB
13Accepted4/43ms3404 KiB
14Accepted4/43ms3608 KiB
15Wrong answer0/239ms5236 KiB
16Time limit exceeded0/2377ms6092 KiB
17Wrong answer0/243ms5532 KiB
18Time limit exceeded0/2381ms6392 KiB