Little Beaver is a beginner programmer and so informatics are his favorite subject. Soon His informatics teacher was going to had a birthday and the Beaver had decided to prepare a present for her. He planted n Flowers in a row on his windowsill and started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The Beaver thinks it is a bad manners to present little flowers. So he decided to come up with some solutions.
There is M days left to the birthday. The height of the i-th Flower (assume that the flowers in the row is numbered from 1 to n F Rom left-to-right) are equal to ai at the moment. At all of the remaining m days the beaver can take a special watering and water W Contigu OUs Flowers (he can do, only once at a day). At this each watered flower grows is a height unit on the. The beaver wants the height of the smallest flower is as large as possible in the end. What maximum height of the smallest flower can he get?
Input
The first line contains space-separated integers n, m and w(1≤ w ≤ n ≤10 5; 1≤ m ≤105). The second line contains space-separated integers a1, a2, ..., a C19>n(1≤ ai ≤109).
Output
Print a single integer-the maximum final height of the smallest flower.
Sample Input
Input
6 2 3
2 2 2 2 1 1
Output
2
Input
2 5 1
5 8
Output
9
Hint
In the first sample beaver can water, the last 3 flowers on the first day. On the next day he may not be water flowers at all. In the end he'll get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has a height of equal to 2. It's impossible to get the height 3 in this test.
/* Sub-enumeration minimum height with the prefix pre represents the number of times from I to n watering, since the width is w so the number of times that is now poured will be reduced to the last total watering times greater than m indicates the height is higher, for the right interval of two points */#include <cstdio># Include <cstring> #include <algorithm>using namespace std;const int inf = 1e9 + 1e6;const int MAX = 1e6 + 10;in T Pre[max], A[max];int N, M, W, sum;bool judge (int x) {int sum = 0; memset (pre, 0, sizeof (pre)); for (int i = 1; I <= n; i++) {Pre[i] + = pre[i-1]; int day = x-(A[i] + pre[i]); if (Day > 0) {sum + = day; Pre[i] + = day; PRE[I+W]-= day; } if (Sum > m) return false; } return true; int main () {while (~scanf ("%d%d%d", &n, &m, &w)) {for (int i = 1; I <= n; i++) {scanf (" %d ", &a[i]); } int L = 1, r = INF; int ans = l; while (L <= r) {int mid = (L + r) >> 1; if (judge (mid)) {L = mid + 1; Ans = mid; } else R = mid-1; } printf ("%d\n", ans); } return 0;}
Codeforces 460c--two points + prefix and--present