結果

問題 No.2217 Suffix+
ユーザー vjudge1
提出日時 2024-02-22 10:45:48
言語 C++14
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 89 ms / 2,000 ms
コード長 742 bytes
コンパイル時間 1,420 ms
コンパイル使用メモリ 165,548 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2024-09-29 04:25:17
合計ジャッジ時間 3,335 ms
ジャッジサーバーID
(参考情報)
judge4 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

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

const int MAXN = 100001;

int n, k;
ll a[MAXN];

bool check(ll x) {
  ll sum = 0, cnt = 0;
  for(int i = 1; i <= n; ++i) {
    if(a[i] + sum < x) {
      ll res = 1ll * (x - a[i] - sum + i - 1ll) / i;
      cnt += res, sum += res * i;
    }
    if(cnt > k) {
      return 0;
    }
  }
  return 1;
}

ll two_bound() {
  ll l = 0ll, r = 200000000000001ll;
  while(l < r) {
    ll mid = (l + r + 1ll) >> 1ll;
    if(check(mid)) {
      l = mid;
    }else {
      r = mid - 1;
    }
  }
  return l;
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> k;
  for(int i = 1; i <= n; ++i) {
    cin >> a[i];
  }
  cout << two_bound();
  return 0;
}
0