#P8170. [eJOI 2021] Waterfront
[eJOI 2021] Waterfront
Problem Description
There are bushes with initial heights . Each bush grows by in height every day.
Every day, after all bushes have finished growing, the gardener will prune the bushes times. Each time, they may choose any bush whose height is at least and cut it shorter by units.
Find the minimum possible value of the height of the tallest bush after days.
Input Format
The first line contains four positive integers .
The next lines each contain two non-negative integers .
Output Format
Output one non-negative integer, the minimum possible height of the tallest bush after days.
4 3 4 3
2 5
3 2
0 4
2 8
8
Hint
Sample Explanation
| Day | Bush Index | Height Change |
|---|---|---|
| $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$ | ||
| $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$ | ||
| $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): , , , .
- Subtask 2 (22 pts): .
- Subtask 3 (43 pts): .
- Subtask 4 (27 pts): .
For of the testdata, , , $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