/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 47ms 540.0 KiB
#3 Accepted 80ms 1.277 MiB
#4 Accepted 84ms 1.305 MiB
#5 Accepted 80ms 1.297 MiB
#6 Accepted 89ms 1.289 MiB
#7 Accepted 80ms 1.289 MiB
#8 Accepted 86ms 1.289 MiB
#9 Accepted 79ms 1.293 MiB
#10 Accepted 80ms 1.277 MiB
#11 Accepted 81ms 1.277 MiB
#12 Accepted 80ms 1.301 MiB
#13 Accepted 80ms 1.07 MiB
#14 Accepted 80ms 1.277 MiB
#15 Accepted 80ms 1.07 MiB
#16 Accepted 100ms 1.305 MiB
#17 Accepted 80ms 1.324 MiB
#18 Accepted 94ms 1.293 MiB
#19 Accepted 96ms 1.277 MiB
#20 Accepted 85ms 1.535 MiB

Code

#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
int main()
{
  
    ll tc;
    cin>>tc;
    while(tc--)
    {
        ll n;
        cin>>n;
        vector<ll>v(n);
        ll s=0;
        for(int i=0;i<n;i++){ cin>>v[i];
                             s+=v[i];
                            }
        ll l=0,r=2e9,ans=-1;
        while(l<=r)
        {
            ll mid=(l+(r-l)/2);
            if((mid*(mid+1))/2<=s)
            {
                ans=mid+1;
                l=mid+1;
            }
            else
                r=mid-1;
        }
        cout<<ans<<endl;
    }
        

}

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:15:32
Judged At
2024-11-05 15:15:32
Judged By
Score
100
Total Time
100ms
Peak Memory
1.535 MiB