/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 16ms 572.0 KiB
#3 Accepted 21ms 1.305 MiB
#4 Accepted 20ms 1.27 MiB
#5 Accepted 21ms 1.27 MiB
#6 Accepted 21ms 1.297 MiB
#7 Accepted 21ms 1.297 MiB
#8 Accepted 21ms 1.27 MiB
#9 Accepted 21ms 1.27 MiB
#10 Accepted 21ms 1.297 MiB
#11 Accepted 21ms 1.301 MiB
#12 Accepted 22ms 1.301 MiB
#13 Accepted 20ms 1.27 MiB
#14 Accepted 21ms 1.27 MiB
#15 Accepted 21ms 1.305 MiB
#16 Accepted 21ms 1.27 MiB
#17 Accepted 21ms 1.27 MiB
#18 Accepted 23ms 1.27 MiB
#19 Accepted 24ms 1.297 MiB
#20 Accepted 24ms 1.297 MiB

Code

#include <bits/stdc++.h>
#define int long long
#define sqrtl(x) sqrt(x)
using namespace std;

namespace solve {
  namespace test_case {
    void main() {
      int n; cin >> n;
      vector<int> a(n);
      for (auto &x: a) cin >> x;
      auto sum = accumulate(a.begin(), a.end(), 0LL);
      int l (0), r (1e9), mex (1);
      while (l <= r) {
        int m ((l + r) / 2);
        if (m * (m + 1) / 2 <= sum) l = m + 1, mex = m + 1;
        else r = m - 1;
      }
      cout << mex << '\n';
    }
  }

  void main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int t (1); cin >> t; 
    while (t--) {
      test_case::main();
    }
  }
}

signed main() { solve::main(); }

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 16:27:27
Judged At
2024-11-05 16:27:27
Judged By
Score
100
Total Time
24ms
Peak Memory
1.305 MiB