93272024-02-20 14:18:40TuruTamasBányász RPG (40 pont)cpp17Accepted 40/4064ms9772 KiB
#include <bits/stdc++.h>
using namespace std;

#ifdef DEBUG
ifstream in_file("C:\\verseny\\minta\\be1.txt");
#define input in_file
#define INTHENAMEOFGOD
#else
#define input cin
#define INTHENAMEOFGOD \
    ios::sync_with_stdio(0); \
    cin.tie(0); \
    cout.tie(0);
#endif
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef pair<ll, ll> pii;

ll N, a, M, akt;
vector<pii> v;

int main() {
    input >> N;
    v.resize(N);
    for (ll n = 0; n < N; n++) {
        input >> a;
        v[n].first = a;
    }
    for (ll n = 0; n < N; n++) {
        input >> a;
        v[n].second = a;
        M += a;
    }
    akt = M;

    sort(v.begin(), v.end(), [](pii &l, pii &r) {
        return l.first > r.first;
    });

    for (pii &p : v) {
        akt -= max(0LL, min(p.second, akt-p.first));
    }

    cout << M + akt << endl;
}
SubtaskSumTestVerdictTimeMemory
base40/40
1Accepted0/03ms1876 KiB
2Accepted0/014ms2688 KiB
3Accepted2/23ms2460 KiB
4Accepted2/23ms2688 KiB
5Accepted2/210ms3328 KiB
6Accepted2/220ms4612 KiB
7Accepted2/24ms4016 KiB
8Accepted2/26ms4144 KiB
9Accepted3/33ms3948 KiB
10Accepted3/33ms4020 KiB
11Accepted3/33ms4256 KiB
12Accepted3/33ms4272 KiB
13Accepted4/43ms4440 KiB
14Accepted4/43ms4256 KiB
15Accepted2/239ms6152 KiB
16Accepted2/250ms7648 KiB
17Accepted2/241ms7792 KiB
18Accepted2/264ms9772 KiB