結果

問題 No.2217 Suffix+
ユーザー merom686
提出日時 2023-02-17 21:41:29
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 85 ms / 2,000 ms
コード長 810 bytes
コンパイル時間 2,086 ms
コンパイル使用メモリ 195,364 KB
最終ジャッジ日時 2025-02-10 16:35:28
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
using ll = long long;

template <class T, class F>
T UpperBound(T i0, T i1, F f) {
    while (i0 < i1) {
        T i = i0 + (i1 - i0) / 2;
        if (f(i)) i0 = i + 1; else i1 = i;
    }
    return i0;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n, k;
    cin >> n >> k;

    vector<ll> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    auto x = UpperBound<ll>(1, (ll)3e14, [&](auto x) {
        ll s = k;
        for (int i = 0; i < n; i++) {
            ll t = x - a[i];
            if (t <= 0) continue;
            t = (t + i) / (i + 1);
            s -= t;
            x -= t * (i + 1);
            if (s < 0) return false;
        }
        return true;
    }) - 1;
    cout << x << endl;

    return 0;
}
0