C - Simplification


  • محدودیت زمان: ۱ ثانیه
  • محدودیت حافظه: ۲۵۶ مگابایت

Amin records the price of his stock every now and then as a data point (ti,pi)(t_i, p_i) in his notebook, where pip_i is the price of his stock at day tit_i. The sequence of these data points represents a piecewise-linear function FF displaying the history of prices over a period of time. Indeed, FF connects every pair of consecutive points by a straight line segment. If the price is not recorded for some day tt, F(t)F(t) 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 FF′ with the remaining points. FF′ is a so-called “simplification” of FF. Amin wants to create the simplification in such a way that FF′ is a good approximation for FF. To this end, he has defined an error measure as follows.

Let FF be defined over a strictly increasing sequence L=t1,,tnL = \langle t_1, \dots, t_n \rangle of days, and FF' be defined over a subsequence L=t1,,tmL' = \langle t'_1, \dots, t'_m \rangle of LL, where t1=t1t'_1 = t_1, tm=tnt'_m = t_n, and F(ti)=F(ti)F'(t'_i) = F(t'_i) for 1im1 \leq i \leq m. (We call mm the size of FF'.) The error of FF' is defined as the maximum of F(tk)F(tk)|F'(t_k) - F(t_k)| for all 1kn1 \leq k \leq n.

For example, in the following figure, we have 66 data points, labeled 11 through 66, whose coordinates are the same as those presented in the second sample input, and FF' is a simplification of FF of size 33 with data points 11, 44, and 66. In this figure, FF is depicted by solid lines, and FF' by dashed lines. The error measure for FF' is realized by the vertical distance of point 22 to FF'.

توضیح تصویر

Amin’s goal is to minimize the size of FF' , while the error of FF' is bounded by a given value δ\delta.

ورودی🔗

The first line of input contains a positive integer nn (2n20002 \leq n \leq 2000) that shows the size of FF. Each of the next nn lines contains two integers tit_i, pip_i (1ti,pi1061 \leq t_i,p_i \leq 10^6), where pip_i is the price of the stock at day tit_i. The last line contains the error limit δ\delta which is a non-negative integer at most 10610^6.

خروجی🔗

In the output, print the minimum possible size of FF'.

مثال‌ها🔗

ورودی نمونه ۱🔗

3
1 10
3 100
10 20
90
Plain text

خروجی نمونه ۱🔗

2
Plain text

ورودی نمونه ۲🔗

6
10 10
20 20
35 14
50 20
60 10
70 10
8
Plain text

خروجی نمونه ۲🔗

3
Plain text
ارسال پاسخ برای این سؤال
در حال حاضر شما دسترسی ندارید.