Accepted
Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
int t;
cin >> t;
while (t--){
ll n, a, mx = 1, S = 0;
cin >> n;
for (int i = 0; i < n; i++){
cin >> a;
S += a;
}
ll l = 0, r = 1e9;
while (l <= r){
ll m = (l + r) / 2;
ll x = (m * (m + 1)) / 2;
if (x <= S){
l = m + 1;
mx = m + 1;
} else {
r = m - 1;
}
}
cout << mx << endl;
}
return 0;
}
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:31:46
- Judged At
- 2024-11-05 15:31:46
- Judged By
- Score
- 100
- Total Time
- 83ms
- Peak Memory
- 548.0 KiB