/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 14ms 568.0 KiB
#3 Accepted 34ms 1.312 MiB
#4 Accepted 34ms 1.27 MiB
#5 Accepted 35ms 1.066 MiB
#6 Accepted 33ms 1.27 MiB
#7 Accepted 40ms 1.309 MiB
#8 Accepted 38ms 1.27 MiB
#9 Accepted 34ms 1.27 MiB
#10 Accepted 41ms 1.27 MiB
#11 Accepted 34ms 1.27 MiB
#12 Accepted 37ms 1.27 MiB
#13 Accepted 34ms 1.316 MiB
#14 Accepted 34ms 1.27 MiB
#15 Accepted 34ms 1.27 MiB
#16 Accepted 34ms 1.27 MiB
#17 Accepted 34ms 1.27 MiB
#18 Accepted 34ms 1.305 MiB
#19 Accepted 34ms 1.27 MiB
#20 Accepted 34ms 1.27 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-05 15:37:03
Judged By
Score
100
Total Time
41ms
Peak Memory
1.316 MiB