結果

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

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+100;
long long n,k;
long long a[MAXN],d[MAXN];
int main() {
  cin >> n >> k;
  for (int i=0; i<n; i++) {
    cin >> a[i];
  }
  long long l=0,r=1e18;
  while (l<r) {
    long long mid=(l+r+1)/2;
    for (int i=0; i<n; i++) {
      d[i]=a[i];
    }
    long long b=0,cnt=0;
    for (int i=0; i<n; i++) {
      d[i]+=b;
      if(d[i]<mid){
          long long p=(mid-d[i]+i)/(i+1);
          cnt+=p;
          b+=p*(i+1);
        }
    }
    //cout << mid << " " << cnt << endl;
    if (cnt<=k) {
      l=mid;
    } else{
      r=mid-1;
    }
  }
  cout << l;
  return 0;
}
0