/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 532.0 KiB
#2 Accepted 40ms 572.0 KiB
#3 Accepted 43ms 536.0 KiB
#4 Accepted 20ms 324.0 KiB
#5 Accepted 22ms 532.0 KiB
#6 Accepted 20ms 532.0 KiB
#7 Accepted 21ms 532.0 KiB
#8 Accepted 41ms 532.0 KiB
#9 Accepted 45ms 324.0 KiB
#10 Accepted 20ms 532.0 KiB
#11 Accepted 20ms 532.0 KiB
#12 Accepted 23ms 532.0 KiB
#13 Accepted 43ms 532.0 KiB
#14 Accepted 48ms 532.0 KiB
#15 Accepted 48ms 532.0 KiB
#16 Accepted 28ms 532.0 KiB
#17 Accepted 24ms 532.0 KiB
#18 Accepted 27ms 324.0 KiB
#19 Accepted 23ms 532.0 KiB
#20 Accepted 20ms 532.0 KiB

Code

#define _GLIBCXX_FILESYSTEM
#include<bits/stdc++.h>
using namespace std;
#define ll long long

void solve() {
    int n;
    cin >> n;
    ll sum = 0;
    for(int i = 0; i < n; i++) {
        ll x;
        cin >> x;
        sum += x;
    }
    ll x, l = 0, r = 1e9, mid;
    while(l <= r) {
        mid = l + (r - l) / 2;
        ll now = mid * mid + mid - 2ll * sum;
        if(now <= 0) {
            x = mid;
            l = mid + 1;
        } else r = mid - 1;
    }
    cout << x + 1 << '\n';
    return;
}

int32_t main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    int tc = 1;
    cin >> tc;
    for(int kase = 1; kase <= tc; kase++) {
        //cout << "Case " << kase << ": ";
        solve();
    }
    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 14:55:16
Judged At
2024-11-05 14:55:16
Judged By
Score
100
Total Time
48ms
Peak Memory
572.0 KiB