int main() { int n, m, x, k; cin >> n >> m >> x >> k; vector<int> nums(n, 0); for (int i = 0; i < n; i++) cin >> nums[i]; int m_min = 50000; for (auto its : nums) m_min = min(its, m_min); int m_max = m_min + m * k; int l = 1; int r = m_max; while (l < r) { int mid = (l + r + 1)/2; vector<int> dp(n, 0); int numm = 0; bool b1 = true; for (int i = 0; i < n; i++) { int num = 0; int r0 = i + x < n ? i + x : n-1; for (int j = i - x>0 ? i - x : 0; j <= r0; j++) { num += dp[j]; } if (num * k + nums[i] >= mid) { continue; } else { int lest = mid - num * k - nums[i]; int num2 = lest / k; if (lest % k != 0) num2++; if (num2 + numm > m) { b1 = false; break; } dp[r0] += num2; numm += num2; } } if (b1) { l = mid; } else r = mid - 1; } cout << (l + r) / 2 << endl; system("pause"); } 二分查找