結果

問題 No.2217 Suffix+
ユーザー tsugutsugu
提出日時 2023-02-17 21:40:57
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 145 ms / 2,000 ms
コード長 719 bytes
コンパイル時間 1,601 ms
コンパイル使用メモリ 169,248 KB
実行使用メモリ 6,944 KB
最終ジャッジ日時 2024-07-19 12:50:32
合計ジャッジ時間 4,443 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

int main() {
    int n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    auto check = [&] (long long x) {
        long long cnt = 0;
        long long y = 0;
        for (int i = 0; i < n; i++) {
            if (a[i] + y < x) {
                long long z = (x - (a[i] + y) + i) / (i + 1);
                y += (long long) (i + 1) * z;
                cnt += z;
            }
        }
        return cnt <= k;
    };
    long long ok = 0, ng = 1e15;
    while (ng - ok > 1) {
        long long mid = (ok + ng) >> 1;
        if (check(mid)) ok = mid;
        else ng = mid;
    }
    cout << ok << endl;
}
0