155232025-02-20 10:41:39antiBányász RPG (40 pont)cpp17Time limit exceeded 26/40400ms844 KiB
#include <iostream>
#include <algorithm>
#include <fstream>

using namespace std;

struct alapanyag{
    int l, m;
};

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

int main()
{
    //ifstream cin("be2.txt");
    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);
    int bal=0, jobb=n-1;
    long long xp = 0, meg = 0;
    while(bal<=jobb){
        if(xp >= A[bal].l){
            xp++;
            A[bal].m--;
            meg += 1;
            if(A[bal].m == 0){
                bal++;
            }
        }
        else{
            xp++;
            A[jobb].m--;
            meg += 2;
            if(A[jobb].m == 0){
                jobb--;
            }
        }
    }
    cout << meg;
}

/*
5
2 3 5 6 7
4 2 2 6 5
*/
SubtaskSumTestVerdictTimeMemory
base26/40
1Accepted0/01ms316 KiB
2Time limit exceeded0/0391ms508 KiB
3Accepted2/21ms316 KiB
4Accepted2/23ms320 KiB
5Time limit exceeded0/2400ms492 KiB
6Time limit exceeded0/2400ms628 KiB
7Accepted2/210ms424 KiB
8Time limit exceeded0/2377ms432 KiB
9Accepted3/31ms316 KiB
10Accepted3/31ms316 KiB
11Accepted3/32ms316 KiB
12Accepted3/310ms316 KiB
13Accepted4/459ms392 KiB
14Accepted4/434ms316 KiB
15Time limit exceeded0/2400ms720 KiB
16Time limit exceeded0/2400ms844 KiB
17Time limit exceeded0/2386ms772 KiB
18Time limit exceeded0/2400ms820 KiB