結果

問題 No.2217 Suffix+
ユーザー vjudge1vjudge1
提出日時 2024-02-22 10:48:17
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 331 ms / 2,000 ms
コード長 926 bytes
コンパイル時間 2,168 ms
コンパイル使用メモリ 202,040 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2024-02-22 10:48:25
合計ジャッジ時間 8,729 ms
ジャッジサーバーID
(参考情報)
judge11 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,676 KB
testcase_01 AC 2 ms
6,676 KB
testcase_02 AC 2 ms
6,676 KB
testcase_03 AC 2 ms
6,676 KB
testcase_04 AC 1 ms
6,676 KB
testcase_05 AC 2 ms
6,676 KB
testcase_06 AC 2 ms
6,676 KB
testcase_07 AC 2 ms
6,676 KB
testcase_08 AC 2 ms
6,676 KB
testcase_09 AC 2 ms
6,676 KB
testcase_10 AC 2 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 2 ms
6,676 KB
testcase_13 AC 2 ms
6,676 KB
testcase_14 AC 70 ms
6,676 KB
testcase_15 AC 70 ms
6,676 KB
testcase_16 AC 154 ms
6,676 KB
testcase_17 AC 111 ms
6,676 KB
testcase_18 AC 84 ms
6,676 KB
testcase_19 AC 228 ms
6,676 KB
testcase_20 AC 199 ms
6,676 KB
testcase_21 AC 26 ms
6,676 KB
testcase_22 AC 218 ms
6,676 KB
testcase_23 AC 153 ms
6,676 KB
testcase_24 AC 299 ms
6,676 KB
testcase_25 AC 331 ms
6,676 KB
testcase_26 AC 305 ms
6,676 KB
testcase_27 AC 303 ms
6,676 KB
testcase_28 AC 304 ms
6,676 KB
testcase_29 AC 305 ms
6,676 KB
testcase_30 AC 304 ms
6,676 KB
testcase_31 AC 303 ms
6,676 KB
testcase_32 AC 299 ms
6,676 KB
testcase_33 AC 309 ms
6,676 KB
testcase_34 AC 308 ms
6,676 KB
testcase_35 AC 2 ms
6,676 KB
testcase_36 AC 305 ms
6,676 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>

using namespace std;

using LL = long long;

const int N = 1e5 + 5;

LL c[N], ok, sum, a[N], now, n, k, l, r, mid, ans;

LL lowbit(LL x){
  return x & -x;
}

LL getsum(LL x){
  for(ans = 0; x > 0; ans += c[x], x -= lowbit(x)){
  }
  return ans;
}

void updata(int i, LL k){
  for(; i <= n; c[i] += k, i += lowbit(i)){
  }
}

bool C(LL x){
  for(int i = 1; i <= n; ++i){
    c[i] = 0;
  }
  for(int i = 1; i <= n; ++i){
    updata(i, a[i] - a[i - 1]);
  }
  sum = 0;
  for(int i = 1; i <= n; ++i){
    now = getsum(i);
    ok = max(0ll, (x - now + i - 1) / i);
    sum += ok;
    updata(i, ok * i), updata(n + 1, -ok * i);
  }
  return sum <= k;
}

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