/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 57ms 548.0 KiB
#3 Accepted 80ms 536.0 KiB
#4 Accepted 78ms 532.0 KiB
#5 Accepted 83ms 540.0 KiB
#6 Accepted 81ms 532.0 KiB
#7 Accepted 81ms 532.0 KiB
#8 Accepted 81ms 320.0 KiB
#9 Accepted 82ms 544.0 KiB
#10 Accepted 81ms 320.0 KiB
#11 Accepted 81ms 324.0 KiB
#12 Accepted 82ms 532.0 KiB
#13 Accepted 81ms 532.0 KiB
#14 Accepted 81ms 320.0 KiB
#15 Accepted 81ms 532.0 KiB
#16 Accepted 81ms 544.0 KiB
#17 Accepted 81ms 532.0 KiB
#18 Accepted 81ms 536.0 KiB
#19 Accepted 81ms 544.0 KiB
#20 Accepted 81ms 344.0 KiB

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