78022024-01-11 10:37:221478Bányász RPG (40 pont)cpp17Wrong answer 36/4068ms6316 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);
    for(int i = 1; i <= n; i++){
        cin >> 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;
    
    while(l <= r){
        while(tp != a[l].first){
            if(a[r].second < a[l].first - tp){
                tp += a[r].second;
                ans += 2 * a[r].second;
                r--;
            }
            else{
                int x = a[l].first - tp;
                tp += x;
                ans += 2 * x;
                a[r].second -= x;
            }
        }
        while(l <= r && tp >= a[l].first){
            tp += a[l].second;
            ans += a[l].second;
            l++;
        }
        /*
        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
base36/40
1Accepted0/03ms2088 KiB
2Accepted0/014ms2832 KiB
3Accepted2/23ms2448 KiB
4Accepted2/23ms2492 KiB
5Accepted2/212ms3000 KiB
6Accepted2/223ms3492 KiB
7Accepted2/24ms3108 KiB
8Accepted2/26ms3028 KiB
9Accepted3/33ms3084 KiB
10Accepted3/32ms3172 KiB
11Accepted3/33ms3296 KiB
12Accepted3/33ms3392 KiB
13Accepted4/43ms3396 KiB
14Accepted4/43ms3520 KiB
15Wrong answer0/241ms4944 KiB
16Accepted2/252ms5592 KiB
17Wrong answer0/243ms5412 KiB
18Accepted2/268ms6316 KiB