/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 540.0 KiB
#2 Accepted 23ms 540.0 KiB
#3 Accepted 21ms 1.277 MiB
#4 Accepted 22ms 1.301 MiB
#5 Accepted 22ms 1.277 MiB
#6 Accepted 22ms 1.277 MiB
#7 Accepted 22ms 1.297 MiB
#8 Accepted 22ms 1.277 MiB
#9 Accepted 22ms 1.305 MiB
#10 Accepted 38ms 1.301 MiB
#11 Accepted 39ms 1.32 MiB
#12 Accepted 22ms 1.484 MiB
#13 Accepted 21ms 1.277 MiB
#14 Accepted 23ms 1.305 MiB
#15 Accepted 22ms 1.277 MiB
#16 Accepted 22ms 1.277 MiB
#17 Accepted 22ms 1.527 MiB
#18 Accepted 22ms 1.5 MiB
#19 Accepted 25ms 1.301 MiB
#20 Accepted 22ms 1.277 MiB

Code

#include <bits/stdc++.h>
#define pb push_back
#define int long long
using namespace std;

const int mod = 998244353;
const int inf = 1e9 + 20;
const int N = 1e5+5;

int32_t main(){
    cin.tie(0); cout.tie(0);
    ios_base::sync_with_stdio(false);
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<int> a(n);
        int sum = 0;
        for(int i = 0; i < n; i++){
            cin>>a[i];
            sum += a[i];
        }

        int l = 0, r = inf;
        while(l < r){
            int m = (l + r)/2;

            if(m * (m + 1) / 2 > sum) r = m;
            else l = m + 1; 
        }
        if(l * (l + 1) / 2 > sum) l--;

        cout<<l + 1<<endl;
    }
    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:03:17
Judged At
2024-11-05 15:03:17
Judged By
Score
100
Total Time
39ms
Peak Memory
1.527 MiB