結果
問題 |
No.2217 Suffix+
|
ユーザー |
![]() |
提出日時 | 2024-02-22 10:53:54 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 163 ms / 2,000 ms |
コード長 | 917 bytes |
コンパイル時間 | 1,881 ms |
コンパイル使用メモリ | 191,048 KB |
最終ジャッジ日時 | 2025-02-19 18:43:10 |
ジャッジサーバーID (参考情報) |
judge4 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 4 |
other | AC * 33 |
ソースコード
#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 = ans = 0; for(int i = 1; i <= n; ++i){ //now = getsum(i); ok = max(0ll, (x - (a[i] + ans) + i - 1) / i); sum += ok; ans += ok * i; } return sum <= k; } int main(){ cin >> n >> k; for(int i = 1; i <= n; ++i){ cin >> a[i]; } l = 0, r = (LL)(2e14); while(l < r){ mid = (l + r + 1) >> 1; if(C(mid)){ l = mid; } else{ r = mid - 1; } } cout << l; return 0; }