77772024-01-11 09:46:541478Bányász RPG (40 pont)cpp17Time limit exceeded 26/40400ms4708 KiB
#include <bits/stdc++.h>  
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int,int> p32;
typedef pair<ll,ll> p64;
typedef pair<double,double> pdd;
typedef vector<ll> v64;
typedef vector<int> v32;
typedef vector<vector<int> > vv32;
typedef vector<vector<ll> > vv64;
typedef vector<vector<p64> > vvp64;
typedef vector<p64> vp64;
typedef vector<p32> vp32;
ll MOD = 998244353;
double eps = 1e-12;
#define forn(i,e) for(ll i = 0; i < e; i++)
#define forsn(i,s,e) for(ll i = s; i < e; i++)
#define rforn(i,s) for(ll i = s; i >= 0; i--)
#define rforsn(i,s,e) for(ll i = s; i >= e; i--)
#define ln "\n"
#define dbg(x) cout<<#x<<" = "<<x<<ln
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define INF 2e18
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
 
int main()
{
    //ifstream cin("in.txt");
    int n;
    cin >> n;

    vector<int> lim(n + 1);
    for(int i = 1; i <= n; i++){
        cin >> lim[i];
    }
    vector<int> amount(n + 1);
    int x = 0;
    for(int i = 1; i <= n; i++){
        cin >> amount[i];
        x += amount[i];
    }

    vector<pair<int, int>> a(n + 1);
    //f = lim
    //s = amount
    for(int i = 1; i <= n; i++){
        a[i].first = lim[i];
        a[i].second = amount[i];
    }

    sort(a.begin(), a.end());
    int tp = 0;
    int l = 1;
    int r = n;
    int ans = 0;
    
    for(int i = 1; i <= x; i++){
        if(tp >= a[l].first){
            ans++;
            a[l].second--;
            if(a[l].second == 0){
                l++;
            }
        }
        else{
            ans += 2;
            a[r].second--;
            if(a[r].second == 0){
                r--;
            }
        }
        tp++;
    }

    cout << ans;



    //ha valamit tudsz 1 perc alatt akkor szedd azt
    //ha nem akkor szedd azt aminek a legnagyobb az lim-je?

    /*
    3 - 1 X
    4 - 5 -> 3
    5 - 1 X
    tp: 1 + 1 + 1 + 1
    ans: 2 + 2 + 2 + 1 + 1 + 1 + 1
    */


}
SubtaskSumTestVerdictTimeMemory
base26/40
1Accepted0/03ms1816 KiB
2Time limit exceeded0/0379ms1604 KiB
3Accepted2/23ms2328 KiB
4Accepted2/24ms2500 KiB
5Time limit exceeded0/2400ms1888 KiB
6Time limit exceeded0/2370ms2292 KiB
7Accepted2/213ms2832 KiB
8Time limit exceeded0/2370ms2872 KiB
9Accepted3/33ms2904 KiB
10Accepted3/33ms2940 KiB
11Accepted3/33ms2936 KiB
12Accepted3/313ms3056 KiB
13Accepted4/461ms3188 KiB
14Accepted4/435ms3264 KiB
15Wrong answer0/241ms4500 KiB
16Time limit exceeded0/2347ms3584 KiB
17Wrong answer0/246ms4708 KiB
18Time limit exceeded0/2360ms3856 KiB