/ SeriousOJ /

Record Detail

Wrong Answer


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Wrong Answer 43ms 576.0 KiB
#3 Wrong Answer 202ms 8.809 MiB

Code

#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define pb push_back
#define mod 1000000007

using namespace std;

void solve()
{
    ll n, i, mex=0;
    cin>> n;
    ll a[n+5], sum=0;
    vector <ll> v;
    map <ll, ll> cnt;
    for(i=0; i<n; i++)
    {
        cin>> a[i];
        cnt[a[i]]++;
        if(cnt[a[i]]==1)    v.pb(a[i]);
        else    sum+=a[i];
    }
    sort(v.begin(), v.end());
    for(i=0; i<v.size(); i++)
    {
        if(mex==v[i])   mex++;
        else if(sum>=mex)
        {
            sum = sum-mex;
            mex++;
            i--;
        }
    }
    while(sum>0)
    {
        if(sum>=mex)
        {
            sum = sum-mex;
            mex++;
            i--;
        }
        else    break;
    }
    cout<< mex << '\n';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
 
    ll T = 1, cs = 1, i, k=0;
    cin >> T;
    //sieve();
    //cin.get();

    while(T--)
    {
        //cout<< "Case " << cs++ << ": ";
        solve();
    }
    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:29:46
Judged At
2024-11-11 02:30:36
Judged By
Score
5
Total Time
202ms
Peak Memory
8.809 MiB