/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 320.0 KiB
#2 Accepted 60ms 556.0 KiB
#3 Accepted 88ms 536.0 KiB
#4 Accepted 88ms 540.0 KiB
#5 Accepted 87ms 536.0 KiB
#6 Accepted 88ms 532.0 KiB
#7 Accepted 86ms 536.0 KiB
#8 Accepted 88ms 540.0 KiB
#9 Accepted 88ms 540.0 KiB
#10 Accepted 87ms 536.0 KiB
#11 Accepted 88ms 536.0 KiB
#12 Accepted 85ms 536.0 KiB
#13 Accepted 87ms 532.0 KiB
#14 Accepted 88ms 540.0 KiB
#15 Accepted 88ms 536.0 KiB
#16 Accepted 88ms 532.0 KiB
#17 Accepted 89ms 536.0 KiB
#18 Accepted 88ms 536.0 KiB
#19 Accepted 88ms 536.0 KiB
#20 Accepted 89ms 540.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-11 02:30:31
Judged By
Score
100
Total Time
89ms
Peak Memory
556.0 KiB