/ SeriousOJ /

Record Detail

Accepted


  
# Status Time Cost Memory Cost
#1 Accepted 1ms 340.0 KiB
#2 Accepted 14ms 576.0 KiB
#3 Accepted 27ms 532.0 KiB
#4 Accepted 43ms 536.0 KiB
#5 Accepted 19ms 532.0 KiB
#6 Accepted 47ms 532.0 KiB
#7 Accepted 18ms 532.0 KiB
#8 Accepted 46ms 532.0 KiB
#9 Accepted 21ms 564.0 KiB
#10 Accepted 29ms 536.0 KiB
#11 Accepted 20ms 532.0 KiB
#12 Accepted 44ms 564.0 KiB
#13 Accepted 19ms 532.0 KiB
#14 Accepted 20ms 532.0 KiB
#15 Accepted 20ms 320.0 KiB
#16 Accepted 20ms 532.0 KiB
#17 Accepted 22ms 532.0 KiB
#18 Accepted 28ms 532.0 KiB
#19 Accepted 23ms 532.0 KiB
#20 Accepted 30ms 532.0 KiB

Code

/**
 *  @author:   Binoy Barman
 *  @created:  2024-11-05 20:56:16
**/

#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);

#ifdef LOCAL
#include "debug/whereisit.hpp"
#else
#define dbg(...) 42
#endif
#define int long long

int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    Too_Many_Jobs {
        int n;
        cin >> n;
        int sum = 0;
        for (int i = 0; i < n; i++) {
            int x;
            cin >> x;
            sum += x;
        }
        int L = 1, H = 2e9, mid, ans = 0;
        while(L <= H) {
            mid = (L + H) / 2;
            int cur = (mid * (mid + 1)) / 2;
            if(cur <= sum) {
                ans = mid;
                L = mid + 1;
            } else {
                H = mid - 1;
            }
        }
        cout << ans + 1 << nl;
    }
    
    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:32:00
Judged At
2024-11-05 15:32:00
Judged By
Score
100
Total Time
47ms
Peak Memory
576.0 KiB