結果

問題 No.2217 Suffix+
ユーザー vjudge1
提出日時 2024-02-22 11:28:07
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 141 ms / 2,000 ms
コード長 701 bytes
コンパイル時間 2,030 ms
コンパイル使用メモリ 192,736 KB
最終ジャッジ日時 2025-02-19 18:43:19
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 33
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>

using namespace std;

long long a[100005], f[100005], b[100005];
long long n, k;

bool C(long long x){
  for(long long i = 1; i <= n; i++){
    b[i] = a[i];
  }
  long long sum = 0, ans = 0;
  for(long long i = 1; i <= n; i++){
    if(b[i] + sum <= x){
      long long u = ceil(1.0 * (x - b[i] - sum) / i);
      ans += u;
      sum += u * i;
    }
  }
  if(ans <= k){
    return 1;
  }
  return 0;
}

int main(){
  cin >> n >> k;
  for(long long i = 1; i <= n; i++){
    cin >> a[i];
  }
  long long l = 0, r = 1e15;
  while(l < r){
    long long mid = (l + r + 1) >> 1;
    if(C(mid)){
      l = mid;
    }
    else{
      r = mid - 1;
    }
  }
  cout << l;
  return 0;
}
0