#P15640. [ICPC 2022 Tehran R] Simplification
[ICPC 2022 Tehran R] Simplification
Problem Description
Amin records the price of his stock every now and then as a data point in his notebook, where is the price of his stock at day . The sequence of these data points represents a piecewise-linear function displaying the history of prices over a period of time. Indeed, connects every pair of consecutive points by a straight line segment. If the price is not recorded for some day , can be used as an estimate instead.
His collected data is getting larger and larger as he has been tracking the price of his stock over a long period of time. Therefore, he has decided to reduce his data by throwing away some of his recoded data points and constructing a new piecewise-linear function with the remaining points. is a so-called "simplification" of . Amin wants to create the simplification in such a way that is a good approximation for . To this end, he has defined an error measure as follows.
Let be defined over a strictly increasing sequence of days, and be defined over a subsequence of , where , , and for . (We call the size of .) The error of is defined as the maximum of for all . For example, in the following figure, we have data points, labeled through , whose coordinates are the same as those presented in the second sample input, and is a simplification of of size with data points , and . In this figure, is depicted by solid lines, and by dashed lines. The error measure for is realized by the vertical distance of point to .
:::align{center}
:::
Amin's goal is to minimize the size of , while the error of is bounded by a given value .
Input Format
The first line of input contains a positive integer () that shows the size of . Each of the next lines contains two integers , (), where is the price of the stock at day . The last line contains the error limit which is a non-negative integer at most .
Output Format
In the output, print the minimum possible size of .
3
1 10
3 100
10 20
90
2
6
10 10
20 20
35 14
50 20
60 10
70 10
8
3