Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <algorithm>
- #include <vector>
- #include <cmath>
- #include <string>
- #include <iomanip>
- #include <set>
- #include <utility>
- #include <vector>
- #include <fstream>
- #include <map>
- #include <deque>
- #include <queue>
- #include <cstring>
- #include <cstdio>
- #include <list>
- #include <bitset>
- using namespace std;
- const long long INF = 1e18;
- const int MAXN = 1e5 + 1, MODM = 1e9 + 7;
- #define ABS(x) ((x) < 0 ? -(x) : (x))
- #define ll long long
- #define ld long double
- #define all(a) a.begin(), a.end()
- #define pii pair<ll, int>
- #define forn(i, n) for(int i = 0; i < n; i++)
- #ifdef DEBUG
- #define NAME "1"
- #else
- #define NAME "landscape"
- #endif
- #define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout)
- #define PI 3.1415926535897932384626433832795
- //#define y second
- //#define x first
- ll n, amount, w[MAXN], pr_sum[MAXN + 1];
- ll ans = 0;
- set<pii> p1, p2;
- int main() {
- ios_base::sync_with_stdio(0);
- FREOPEN;
- cin >> n >> amount;
- forn(i, n)
- cin >> w[i];
- pr_sum[0] = 0;
- forn(i, n)
- pr_sum[i + 1] = pr_sum[i] + w[i];
- forn(i, n)
- p2.insert(pii(w[i] + i, i));
- forn(i, n) {
- auto it = pii(w[i] + i, i);
- p2.erase(it);
- it = pii(w[i] - i, i);
- if(i == 0 || i == n - 1) {
- ans = max(ans, w[i]);
- p1.insert(it);
- continue;
- }
- ll l = w[i], r = 2e18;
- while(r - l > 1) {
- ll h = (l + r) / 2;
- auto it_l = p1.lower_bound(pii(h - i, -1));
- auto it_r = p2.lower_bound(pii(h + i, -1));
- bool fl = 1;
- if(it_l == p1.end() || it_r == p2.end()) {
- fl = 0;
- }
- else {
- int j_l = it_l->second;
- j_l++;
- int j_r = it_r->second;
- j_r--;
- ll need = 0;
- need += max(0LL, ((h + h - ABS(i - j_l)) * (ABS(i - j_l) + 1) / 2) - (pr_sum[i + 1] - pr_sum[j_l]));
- need += max(0LL, ((h + h - ABS(i - j_r)) * (ABS(i - j_r) + 1) / 2) - (pr_sum[j_r + 1] - pr_sum[i]));
- need -= (h - w[i]);
- fl = (need <= amount);
- }
- if(fl)
- l = h;
- else
- r = h;
- }
- ans = max(ans, l);
- p1.insert(it);
- }
- cout << ans;
- //#ifdef DEBUG
- // cout << "\n\nTIME ELAPSED: " << ((float)clock()) / CLOCKS_PER_SEC << "\n";
- //#endif
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement