/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 536.0 KiB
#2 Accepted 31ms 532.0 KiB
#3 Accepted 20ms 1.062 MiB
#4 Accepted 21ms 1.07 MiB
#5 Accepted 21ms 1.27 MiB
#6 Accepted 19ms 1.312 MiB
#7 Accepted 22ms 1.27 MiB
#8 Accepted 23ms 1.273 MiB
#9 Accepted 20ms 1.059 MiB
#10 Accepted 26ms 1.27 MiB
#11 Accepted 45ms 1.27 MiB
#12 Accepted 21ms 1.27 MiB
#13 Accepted 46ms 1.285 MiB
#14 Accepted 19ms 1.309 MiB
#15 Accepted 21ms 1.066 MiB
#16 Accepted 45ms 1.27 MiB
#17 Accepted 21ms 1.312 MiB
#18 Accepted 21ms 1.062 MiB
#19 Accepted 19ms 1.27 MiB
#20 Accepted 20ms 1.27 MiB

Code

#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long int
#define N (ll)1e6
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll t=1,i=1,j,p,mx,tot,n,a,m,x,y,k,rt,c,b=1;
    cin>>t;
    while(t--){
        cin>>n;
        ll ar[n],s=0,hi,lo,mid;
        for(a=0;a<n;a++){
            cin>>ar[a];
            s+=ar[a];
        }
        lo=0;hi=1e8;
        while(hi-lo>1){
            mid=(hi+lo)/2;
            if(mid*(mid+1)/2>s)
                hi=mid-1;
            else
                lo=mid;
        }
        if(hi*(hi+1)/2<=s)
            cout<<hi+1<<endl;
        else
            cout<<lo+1<<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:04:08
Judged At
2024-11-05 15:04:08
Judged By
Score
100
Total Time
46ms
Peak Memory
1.312 MiB