Accepted
Code
#include <iostream>
#include <cmath>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while(t--) {
int n;
cin >> n;
long long sum = 0;
for(int i = 0; i < n; i++) {
int x;
cin >> x;
sum += x;
}
// Solve k*(k+1)/2 <= sum
// Using quadratic formula: k = floor((-1 + sqrt(1 + 8*sum)) / 2)
long long k = static_cast<long long>(floor((-1.0 + sqrt(1 + 8.0 * sum)) / 2));
cout << k + 1 << "\n";
}
return 0;
}
Information
- Submit By
- Type
- Submission
- Problem
- P1114 Maximize the MEX
- Language
- C++17 (G++ 13.2.0)
- Submit At
- 2025-02-21 17:35:58
- Judged At
- 2025-02-21 17:35:58
- Judged By
- Score
- 100
- Total Time
- 47ms
- Peak Memory
- 588.0 KiB