/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 15ms 532.0 KiB
#3 Accepted 22ms 1.316 MiB
#4 Accepted 22ms 1.297 MiB
#5 Accepted 44ms 1.27 MiB
#6 Accepted 30ms 1.27 MiB
#7 Accepted 25ms 1.316 MiB
#8 Accepted 20ms 1.273 MiB
#9 Accepted 24ms 1.301 MiB
#10 Accepted 21ms 1.301 MiB
#11 Accepted 44ms 1.301 MiB
#12 Accepted 47ms 1.297 MiB
#13 Accepted 48ms 1.297 MiB
#14 Accepted 21ms 1.301 MiB
#15 Accepted 24ms 1.293 MiB
#16 Accepted 20ms 1.312 MiB
#17 Accepted 26ms 1.27 MiB
#18 Accepted 39ms 1.301 MiB
#19 Accepted 20ms 1.32 MiB
#20 Accepted 20ms 1.301 MiB

Code

#ifndef LOCAL
#include <bits/stdc++.h>
#define debug(...)
#endif

using namespace std;
#define int long long
#define cinv(v) for (auto &it:v) cin>>it;
#define coutv(v) for (auto &it:v) cout<< it<<' '; cout<<'\n';

const int INF = 1e8;

void shelby() {
    int n;
    cin >> n;
    vector<int> v(n);
    cinv(v)
    int sum = accumulate(v.begin(), v.end(), 0LL);
    auto ok = [&](int x)-> bool {
        return x * (x + 1) / 2 <= sum;
    };
    int l = 0, r = INF, ans;
    while (l <= r) {
        int m = (l + r) / 2;
        if (ok(m)) ans = m, l = m + 1;
        else r = m - 1;
    }
    cout << ans + 1 << '\n';
}

signed main() {
    cin.tie(0)->sync_with_stdio(0);
    int t = 1;
    cin >> t;
    for (int _ = 1; _ <= t; ++_) {
        // cout << "Case " << _ << ": ";
        shelby();
    }
}

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:15:45
Judged At
2024-11-05 15:15:45
Judged By
Score
100
Total Time
48ms
Peak Memory
1.32 MiB