/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 2ms 328.0 KiB
#2 Accepted 30ms 588.0 KiB
#3 Accepted 39ms 952.0 KiB
#4 Accepted 38ms 952.0 KiB
#5 Accepted 38ms 952.0 KiB
#6 Accepted 38ms 944.0 KiB
#7 Accepted 39ms 948.0 KiB
#8 Accepted 40ms 952.0 KiB
#9 Accepted 32ms 952.0 KiB
#10 Accepted 40ms 952.0 KiB
#11 Accepted 40ms 948.0 KiB
#12 Accepted 40ms 816.0 KiB
#13 Accepted 37ms 952.0 KiB
#14 Accepted 39ms 948.0 KiB
#15 Accepted 40ms 956.0 KiB
#16 Accepted 38ms 840.0 KiB
#17 Accepted 38ms 844.0 KiB
#18 Accepted 38ms 912.0 KiB
#19 Accepted 38ms 844.0 KiB
#20 Accepted 37ms 956.0 KiB

Code

#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T> using pbds = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define ll long long
#define hello() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define nl "\n"
#define yes cout<<"YES"<<nl
#define no cout<<"NO"<<nl
#define ss second
#define ff first
#define all(v) v.begin(),v.end()
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pb push_back
#define mod 1000000007
#define mem(a,x) memset(a,x,sizeof(a))
int bit(ll a,int i){if(a&(1LL<<i)) return 1;return 0;}
int dx[]={1,-1,0,0,1,1,-1,-1};
int dy[]={0,0,1,-1,1,-1,1,-1};
ll isqrt (ll x){ll ans = 0;for (ll k = 1LL << 30; k != 0; k /= 2){if ((ans + k) * (ans + k) <= x) {ans += k;}}return ans;}
ll bin(ll n,ll pow){ll result=1;while(pow){if(pow&1){result=(result * n);}n=(n*n);pow>>=1;}return result;}
ll binmod(ll a,ll b,ll MOD){ll ans=1;a%=MOD;while(b){if(b&1)ans=(ans*a)%MOD;b/=2;a=(a*a)%MOD;}return ans;}
ll inverse(ll a,ll MOD){return binmod(a,MOD-2,MOD);}
const int N=2e5+12;
const  int M=998244353;

void solve(){

    int n;
    cin>>n;
    vector<int>a(n);
    multiset<int>st;
    ll sm=0;
    for(int i=0;i<n;i++){
       cin>>a[i];
       sm+=a[i];
    }
    ll l=1,r=2e8,ans=0;
    while(l<=r){
        ll mid=(l+r)/2;
        if(mid*(mid+1)/2<=sm){
            l=mid+1;ans=mid;
        }
        else r=mid-1;
    }
    cout<<ans+1<<nl;
}

int main()
{
    hello();
cout.precision(10); cout.setf(ios::fixed);

    int tc;
    cin>>tc;
  for(int j=1;j<=tc;j++){
  //  cout<<"Case #"<<j<<": ";
       solve();
   }
}

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:32
Judged At
2024-11-11 02:30:37
Judged By
Score
100
Total Time
40ms
Peak Memory
956.0 KiB