/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 504.0 KiB
#2 Accepted 61ms 552.0 KiB
#3 Accepted 97ms 1.273 MiB
#4 Accepted 90ms 1.285 MiB
#5 Accepted 88ms 1.285 MiB
#6 Accepted 88ms 1.293 MiB
#7 Accepted 96ms 1.293 MiB
#8 Accepted 89ms 1.293 MiB
#9 Accepted 89ms 1.297 MiB
#10 Accepted 90ms 1.293 MiB
#11 Accepted 90ms 1.062 MiB
#12 Accepted 91ms 1.297 MiB
#13 Accepted 89ms 1.301 MiB
#14 Accepted 89ms 1.285 MiB
#15 Accepted 89ms 1.285 MiB
#16 Accepted 90ms 1.285 MiB
#17 Accepted 89ms 1.289 MiB
#18 Accepted 95ms 1.285 MiB
#19 Accepted 90ms 1.289 MiB
#20 Accepted 89ms 1.066 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-11 02:31:33
Judged By
Score
100
Total Time
97ms
Peak Memory
1.301 MiB