結果

問題 No.2217 Suffix+
ユーザー vjudge1
提出日時 2023-08-29 11:54:42
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 130 ms / 2,000 ms
コード長 694 bytes
コンパイル時間 1,982 ms
コンパイル使用メモリ 192,408 KB
最終ジャッジ日時 2025-02-16 15:31:11
ジャッジサーバーID
(参考情報)
judge4 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;
using ll = unsigned long long;

const int maxn = 1e5 + 5;

ll n, k, ma = 1e18, a[maxn], b[maxn];

bool check(ll x){
  for(int i = 1; i <= n; i++){
    b[i] = (x > a[i] ? x - a[i] : ll(0));
  }
  ll c = 0, s = 0;
  for(int i = 1; i <= n; i++){
    if(b[i] > s){
      c += (b[i] - s + i - 1) / i;
      s += (b[i] - s + i - 1) / i * i;
    }
  }
  return c <= k;
}

int main(){
  cin >> n >> k;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    ma = min(ma, a[i]);
  }
  ll l = 0, r = n * k + ma;
  while(l < r){
    ll mid = (l + r + 1) / 2;
    if(check(mid)){
      l = mid;
    } else {
      r = mid - 1;
    }
  }
  cout << l;
  return 0;
}
0