/ SeriousOJ /

Record Detail

Runtime Error


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 584.0 KiB
#2 Accepted 73ms 572.0 KiB
#3 Runtime Error 54ms 5.164 MiB
#4 Runtime Error 53ms 5.27 MiB

Code

/**
 *  @author:   Binoy Barman
 *  @created:  2024-11-05 20:56:16
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "debug/whereisit.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        int n;
        cin >> n;
        vector<bool> mex(n + 1, 0);
        multiset<int> f;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            f.insert(x);
        }
        mex[0] = 1;
        int l = 1;
        while(1) {
            if(f.count(l)) {
                mex[l] = 1;
                f.erase(f.find(l));
                l++;
            } else {
                auto it = f.rbegin();
                int cur = 0;
                while(it != f.rend()) {
                    if(cur >= l) break;
                    cur += *it;
                    auto k = it;
                    f.erase(f.find(*it));
                    it = f.rbegin();
                }
                if(cur < l) break;
                mex[l] = 1;
                f.insert(cur - l);
                l++;
            }
        }
        cout << l << nl;
    }
    
    return 0;
}

Information

Submit By
Type
Submission
Problem
P1114 Maximize the MEX
Contest
Brain Booster #7
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-05 15:19:35
Judged At
2024-11-05 15:19:35
Judged By
Score
10
Total Time
73ms
Peak Memory
5.27 MiB