/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 15ms 584.0 KiB
#3 Accepted 36ms 1.305 MiB
#4 Accepted 37ms 1.309 MiB
#5 Accepted 37ms 1.309 MiB
#6 Accepted 36ms 1.27 MiB
#7 Accepted 37ms 1.312 MiB
#8 Accepted 36ms 1.312 MiB
#9 Accepted 36ms 1.312 MiB
#10 Accepted 36ms 1.312 MiB
#11 Accepted 37ms 1.062 MiB
#12 Accepted 36ms 1.07 MiB
#13 Accepted 37ms 1.062 MiB
#14 Accepted 37ms 1.062 MiB
#15 Accepted 36ms 1.309 MiB
#16 Accepted 36ms 1.309 MiB
#17 Accepted 36ms 1.305 MiB
#18 Accepted 36ms 1.301 MiB
#19 Accepted 36ms 1.309 MiB
#20 Accepted 36ms 1.305 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;
    for(i=0; i<n; i++)
    {
        cin>> a[i];
        sum+=a[i];
    }
    while(sum>0)
    {
        if(sum>=mex)
        {
            sum = sum-mex;
            mex++;
        }
        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:37:03
Judged At
2024-11-11 02:30:22
Judged By
Score
100
Total Time
37ms
Peak Memory
1.312 MiB