65642023-12-11 19:08:21horvathabelBányász RPG (40 pont)cpp17Accepted 40/4037ms9096 KiB
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll xp=0, t=0;
    ll cnt=0;
    deque<pair<ll,ll>> q;
    vector<pair<ll,ll>> seg;
    for (int i=0; i<n;i++){
        ll x;
        cin>>x;
        seg.push_back({x,0});
    }
    for (int i=0; i<n;i++){
        ll x;
        cin>>x;
        seg[i].second=x;
    }
    for (pair<ll, ll> i:seg) q.push_back(i);
    sort(q.begin(), q.end());
    while (!q.empty()){
        while (xp<q.front().first){
            if (q.back().second==0) q.pop_back();
            q.back().second--;
            xp++;
            t+=2;
        }
        if (xp>=q.front().first){
            t+=q.front().second;
            xp+=q.front().second;
            q.pop_front();
        }
    }
    cout<<t;

    }


SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1832 KiB
2Accepted0/08ms2864 KiB
3Accepted2/23ms2260 KiB
4Accepted2/23ms2608 KiB
5Accepted2/28ms3488 KiB
6Accepted2/214ms4580 KiB
7Accepted2/24ms3060 KiB
8Accepted2/24ms3324 KiB
9Accepted3/33ms3052 KiB
10Accepted3/33ms3036 KiB
11Accepted3/33ms2952 KiB
12Accepted3/33ms2968 KiB
13Accepted4/43ms3240 KiB
14Accepted4/43ms3328 KiB
15Accepted2/221ms6352 KiB
16Accepted2/229ms7464 KiB
17Accepted2/224ms6956 KiB
18Accepted2/237ms9096 KiB