結果

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

ソースコード

diff #

#include<bits/stdc++.h>
#define int __int128

using namespace std;
const int MAXN = 1e5 + 5;
int n, k, a[MAXN], minn = 1e22, b[MAXN];
int read(){
  string s;
  cin >> s;
  int cnt = 0;
  for (int i = 0; i < s.size(); i++){
    cnt = cnt * 10 + s[i] - '0';
  }
  return cnt;
}
void print(int x){
  if (x < 10){
    signed p = x;
    cout << p;
    return ;
  }
  print(x / 10);
  signed p = x % 10;
  cout << p;
}
bool check(int x){
  int p = 0, q = 0;
  for (int i = 1; i <= n; i++){
    b[i] = max(int(0), x - a[i]);
  }
  for (int i = 1; i <= n; i++){
    if (b[i] > q){
      p += (b[i] - q + i - 1) / i;
      q += (b[i] - q + i - 1) / i * i;
    }
  }
  return p <= k;
}
signed main(){
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  n = read(), k = read();
  for (int i = 1; i <= n; i++){
    a[i] = read();
  }
  int l = 0, r = 1e20;
  while (l < r){
    int mid = (l + r + 1) >> 1;
    if (check(mid)){
      l = mid;
    }else {
      r = mid - 1;
    }
  }
  print(l);
  return 0;
}//
0