/ SeriousOJ /

Record Detail

Time Exceeded


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 71ms 572.0 KiB
#3 Time Exceeded ≥1001ms ≥5.02 MiB
#4 Time Exceeded ≥1100ms ≥4.922 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;
        multiset<int> f;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            f.insert(x);
        }
        int l = 1;
        while(1) {
            auto mew = f.find(l);
            if(mew != f.end()) {
                f.erase(mew);
                l++;
            } else {
                auto it = f.rbegin();
                int cur = 0;
                while(it != f.rend()) {
                    if(cur >= l) break;
                    cur += *it;
                    f.erase(f.find(*it));
                    it = f.rbegin();
                }
                if(cur < l) break;
                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:24:37
Judged At
2024-11-05 15:24:37
Judged By
Score
10
Total Time
≥1100ms
Peak Memory
≥5.02 MiB