/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 392.0 KiB
#2 Accepted 17ms 584.0 KiB
#3 Accepted 22ms 948.0 KiB
#4 Accepted 22ms 952.0 KiB
#5 Accepted 22ms 836.0 KiB
#6 Accepted 22ms 788.0 KiB
#7 Accepted 22ms 948.0 KiB
#8 Accepted 22ms 948.0 KiB
#9 Accepted 22ms 944.0 KiB
#10 Accepted 22ms 836.0 KiB
#11 Accepted 22ms 948.0 KiB
#12 Accepted 22ms 836.0 KiB
#13 Accepted 22ms 952.0 KiB
#14 Accepted 22ms 952.0 KiB
#15 Accepted 22ms 792.0 KiB
#16 Accepted 22ms 944.0 KiB
#17 Accepted 22ms 788.0 KiB
#18 Accepted 22ms 836.0 KiB
#19 Accepted 22ms 944.0 KiB
#20 Accepted 22ms 944.0 KiB

Code

// Created on: 2024-11-05 20:16
// Author: Safwan_Ibrahim

#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl '\n'

bool ok(int x,ll have) {
    ll sum = 1LL * x * (x + 1) / 2;
    return sum > have;
}

void solve()
{
    int n; cin >> n;
    int a[n + 1];
    ll sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }

    int ans = 1;
    int lo = 1, hi = 1e9 + 7;
    while(lo <= hi) {
        int mid = lo + (hi - lo) / 2;
        if (ok(mid,sum)) {
            ans = mid;
            hi = mid - 1;
        }
        else {
            lo = mid + 1;
        }
    }     
    
    cout << ans << endl;
}

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t = 1; cin >> t;
    while(t--) 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 15:22:38
Judged At
2024-11-11 02:30:47
Judged By
Score
100
Total Time
22ms
Peak Memory
952.0 KiB