1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
using namespace std; typedef long long ll; ll p, k, n; ll a[1000010], tot[1000010]; struct { ll cnt, cnti, cnti2; inline void clear() { cnt = cnti = cnti2 = 0; } inline void add(ll i, ll k) { cnt += k; cnti += k * i; cnti2 += k * i * i; } inline ll get(ll i) { return (p - i * i) * cnt + 2 * cnti * i - cnti2; } } d; inline ll check() { ll maxdis = 0, sum = 0; d.clear(); for(; maxdis <= n && maxdis * maxdis <= p; maxdis++); for(ll i = n; i > 0; i--) { if(i + maxdis <= n) d.add(i + maxdis, -tot[i + maxdis]); ll rest = a[i] - d.get(i); if(rest < 0) tot[i] = 0; else tot[i] = rest / p + 1; d.add(i, tot[i]); sum += tot[i]; } return sum <= k; } int main() { scanf("%lld%lld", &n, &k); for(ll i = 1; i <= n; i++) scanf("%lld", a + i); ll ans, l = 1, r = 3e11; while(l <= r) { p = (l + r) >> 1; if(check()) ans = p, r = p - 1; else l = p + 1; } return cout << ans << endl, 0; }
|
近期评论