/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 372.0 KiB
#2 Accepted 49ms 560.0 KiB
#3 Accepted 84ms 1.301 MiB
#4 Accepted 80ms 1.293 MiB
#5 Accepted 82ms 1.477 MiB
#6 Accepted 83ms 1.305 MiB
#7 Accepted 87ms 1.289 MiB
#8 Accepted 80ms 1.293 MiB
#9 Accepted 81ms 1.301 MiB
#10 Accepted 80ms 1.289 MiB
#11 Accepted 81ms 1.277 MiB
#12 Accepted 101ms 1.277 MiB
#13 Accepted 80ms 1.285 MiB
#14 Accepted 80ms 1.293 MiB
#15 Accepted 80ms 1.293 MiB
#16 Accepted 82ms 1.289 MiB
#17 Accepted 81ms 1.277 MiB
#18 Accepted 82ms 1.285 MiB
#19 Accepted 80ms 1.277 MiB
#20 Accepted 80ms 1.277 MiB

Code

#include<bits/stdc++.h>
using namespace std; 
char nl = '\n';
using i64 = long long;

void solve(int t) {
    // cout << "test #" << t << nl;
    i64 n; cin >> n;
    vector<i64> A(n);
    for (auto& a : A) cin >> a;
    i64 sum = accumulate(A.begin(), A.end(), 0LL);
    i64 s = 0, e = 2e9;
    i64 ans = 0;
    while (s <= e) {
        i64 mid = (s + e) >> 1;
        i64 cnt = (mid * (mid + 1)) / 2LL;
        if (cnt <= sum) {
            ans = mid + 1;
            s = mid + 1;
        } else {
            e = mid - 1;
        }
    }
    cout << ans << nl;
} 

int main() {
    int tt = 1;
    cin >> tt;
    for(int t = 1; t <= tt; t++) solve(t);
}

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:06:09
Judged At
2024-11-05 15:06:09
Judged By
Score
100
Total Time
101ms
Peak Memory
1.477 MiB