/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 324.0 KiB
#2 Accepted 34ms 580.0 KiB
#3 Accepted 22ms 1.316 MiB
#4 Accepted 23ms 1.301 MiB
#5 Accepted 22ms 1.309 MiB
#6 Accepted 22ms 1.312 MiB
#7 Accepted 22ms 1.312 MiB
#8 Accepted 22ms 1.297 MiB
#9 Accepted 22ms 1.312 MiB
#10 Accepted 23ms 1.316 MiB
#11 Accepted 22ms 1.312 MiB
#12 Accepted 22ms 1.27 MiB
#13 Accepted 23ms 1.301 MiB
#14 Accepted 23ms 1.316 MiB
#15 Accepted 22ms 1.312 MiB
#16 Accepted 22ms 1.312 MiB
#17 Accepted 23ms 1.301 MiB
#18 Accepted 22ms 1.301 MiB
#19 Accepted 22ms 1.316 MiB
#20 Accepted 22ms 1.316 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-11 02:31:43
Judged By
Score
100
Total Time
34ms
Peak Memory
1.316 MiB