Advertisement
Guest User

Untitled

a guest
Aug 28th, 2016
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.17 KB | None | 0 0
  1. #include <iostream>
  2. #include <algorithm>
  3. #include <vector>
  4. #include <cmath>
  5. #include <string>
  6. #include <iomanip>
  7. #include <set>
  8. #include <utility>
  9. #include <vector>
  10. #include <fstream>
  11. #include <map>
  12. #include <deque>
  13. #include <queue>
  14. #include <cstring>
  15. #include <cstdio>
  16. #include <list>
  17. #include <bitset>
  18.  
  19. using namespace std;
  20.  
  21. const long long INF = 1e18;
  22. const int MAXN = 1e5 + 1, MODM = 1e9 + 7;
  23.  
  24. #define ABS(x) ((x) < 0 ? -(x) : (x))
  25. #define ll long long
  26. #define ld long double
  27. #define all(a) a.begin(), a.end()
  28. #define pii pair<ll, int>
  29. #define forn(i, n) for(int i = 0; i < n; i++)
  30. #ifdef DEBUG
  31. #define NAME "1"
  32. #else
  33. #define NAME "landscape"
  34. #endif
  35. #define FREOPEN freopen(NAME".in", "r", stdin); freopen(NAME".out", "w", stdout)
  36. #define PI 3.1415926535897932384626433832795
  37. //#define y second
  38. //#define x first
  39. ll n, amount, w[MAXN], pr_sum[MAXN + 1];
  40. ll ans = 0;
  41. set<pii> p1, p2;
  42.  
  43. int main() {
  44. ios_base::sync_with_stdio(0);
  45. FREOPEN;
  46. cin >> n >> amount;
  47. forn(i, n)
  48. cin >> w[i];
  49. pr_sum[0] = 0;
  50. forn(i, n)
  51. pr_sum[i + 1] = pr_sum[i] + w[i];
  52. forn(i, n)
  53. p2.insert(pii(w[i] + i, i));
  54. forn(i, n) {
  55. auto it = pii(w[i] + i, i);
  56. p2.erase(it);
  57. it = pii(w[i] - i, i);
  58. if(i == 0 || i == n - 1) {
  59. ans = max(ans, w[i]);
  60. p1.insert(it);
  61. continue;
  62. }
  63. ll l = w[i], r = 2e18;
  64. while(r - l > 1) {
  65. ll h = (l + r) / 2;
  66. auto it_l = p1.lower_bound(pii(h - i, -1));
  67. auto it_r = p2.lower_bound(pii(h + i, -1));
  68. bool fl = 1;
  69. if(it_l == p1.end() || it_r == p2.end()) {
  70. fl = 0;
  71. }
  72. else {
  73. int j_l = it_l->second;
  74. j_l++;
  75. int j_r = it_r->second;
  76. j_r--;
  77. ll need = 0;
  78. need += max(0LL, ((h + h - ABS(i - j_l)) * (ABS(i - j_l) + 1) / 2) - (pr_sum[i + 1] - pr_sum[j_l]));
  79. need += max(0LL, ((h + h - ABS(i - j_r)) * (ABS(i - j_r) + 1) / 2) - (pr_sum[j_r + 1] - pr_sum[i]));
  80. need -= (h - w[i]);
  81. fl = (need <= amount);
  82. }
  83. if(fl)
  84. l = h;
  85. else
  86. r = h;
  87. }
  88. ans = max(ans, l);
  89. p1.insert(it);
  90. }
  91. cout << ans;
  92. //#ifdef DEBUG
  93. // cout << "\n\nTIME ELAPSED: " << ((float)clock()) / CLOCKS_PER_SEC << "\n";
  94. //#endif
  95. return 0;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement