/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 15ms 800.0 KiB
#3 Accepted 21ms 332.0 KiB
#4 Accepted 22ms 540.0 KiB
#5 Accepted 21ms 540.0 KiB
#6 Accepted 21ms 540.0 KiB
#7 Accepted 21ms 556.0 KiB
#8 Accepted 21ms 612.0 KiB
#9 Accepted 21ms 580.0 KiB
#10 Accepted 20ms 540.0 KiB
#11 Accepted 21ms 540.0 KiB
#12 Accepted 21ms 328.0 KiB
#13 Accepted 20ms 568.0 KiB
#14 Accepted 21ms 512.0 KiB
#15 Accepted 21ms 540.0 KiB
#16 Accepted 21ms 564.0 KiB
#17 Accepted 21ms 568.0 KiB
#18 Accepted 20ms 540.0 KiB
#19 Accepted 21ms 560.0 KiB
#20 Accepted 21ms 540.0 KiB

Code

#include<bits/stdc++.h>
using namespace std;
const long long M=2e5+10,MOD=998244353;
typedef long long ll;
#define debug(x) cout<<x<<endl

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t=1;
    cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	ll sum=0;
    	for(int i=1;i<=n;i++){
    		ll a;
    		cin>>a;
    		sum+=a;
    	}
    	ll ans=1;
    	ll l=1,r=1e9;
    	while(l<=r){
    		ll mid=l+(r-l)/2;
    		ll d= mid*(mid+1)/2;
    		if(d<=sum){
    			ans=mid+1;
    			l=mid+1;
    		}
    		else{
    			r=mid-1;
    		}
    	}
    	cout<<ans<<"\n";
    	
    	

    }
    

    
    return 0;
 
}

Information

Submit By
Type
Submission
Problem
P1114 Maximize the MEX
Language
C++17 (G++ 13.2.0)
Submit At
2024-11-12 18:34:13
Judged At
2024-11-12 18:34:13
Judged By
Score
100
Total Time
22ms
Peak Memory
800.0 KiB