#P8170. [eJOI 2021] Waterfront

[eJOI 2021] Waterfront

Problem Description

There are NN bushes with initial heights heighti\textit{height}_i. Each bush grows by dailyGrowthi\textit{dailyGrowth}_i in height every day.

Every day, after all bushes have finished growing, the gardener will prune the bushes kk times. Each time, they may choose any bush whose height is at least xx and cut it shorter by xx units.

Find the minimum possible value of the height of the tallest bush after MM days.

Input Format

The first line contains four positive integers N,M,k,xN, M, k, x.

The next NN lines each contain two non-negative integers heighti,dailyGrowthi\textit{height}_i, \textit{dailyGrowth}_i.

Output Format

Output one non-negative integer, the minimum possible height of the tallest bush after MM days.

4 3 4 3
2 5
3 2
0 4
2 8
8

Hint

Sample Explanation

Day Bush Index Height Change
11 12341 \\ 2 \\ 3 \\ 4 $2 \overset{+5}{\to} 7 \overset{-3}{\to} 4 \\ 3 \overset{+2}{\to} 5 \\ 0 \overset{+4}{\to} 4 \\ 2 \overset{+8}{\to} 10 \overset{-3}{\to} 7 \overset{-3}{\to} 4 \overset{-3}{\to} 1$
22 $4 \overset{+5}{\to} 9 \overset{-3}{\to} 6 \overset{-3}{\to} 3 \\ 5 \overset{+2}{\to} 7 \\ 4 \overset{+4}{\to} 8 \\ 1 \overset{+8}{\to} 9 \overset{-3}{\to} 6 \overset{-3}{\to} 3$
33 $3 \overset{+5}{\to} 8 \\ 7 \overset{+2}{\to} 9 \overset{-3}{\to} 6 \\ 8 \overset{+4}{\to} 12 \overset{-3}{\to} 9 \overset{-3}{\to} 6 \\ 3 \overset{+8}{\to} 11 \overset{-3}{\to} 8$

Constraints

This problem uses bundled testdata.

  • Subtask 1 (8 pts): 1N1001 \le N \le 100, M=k=x=1M = k = x = 1, heighti1\textit{height}_i \ge 1, dailyGrowthi=0\textit{dailyGrowth}_i = 0.
  • Subtask 2 (22 pts): 1N,M5001 \le N, M \le 500.
  • Subtask 3 (43 pts): 1N,M50001 \le N, M \le 5000.
  • Subtask 4 (27 pts): 1N,M1041 \le N, M \le 10^4.

For 100%100\% of the testdata, 1k10001 \le k \le 1000, 1x1041 \le x \le 10^4, $0 \le \textit{height}_i, \textit{dailyGrowth}_i \le 10^4$.

Notes

This problem is translated from eJOI2021 Day 2 C Waterfront。

Translated by ChatGPT 5