結果
問題 |
No.2217 Suffix+
|
ユーザー |
![]() |
提出日時 | 2024-02-22 10:48:17 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 321 ms / 2,000 ms |
コード長 | 926 bytes |
コンパイル時間 | 1,971 ms |
コンパイル使用メモリ | 192,828 KB |
最終ジャッジ日時 | 2025-02-19 18:43:00 |
ジャッジサーバーID (参考情報) |
judge5 / judge1 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
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 = 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; }