Accepted
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
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2024-11-09 07:21:43
- Judged At
- 2024-11-11 02:22:35
- Judged By
- Score
- 100
- Total Time
- 90ms
- Peak Memory
- 1.496 MiB