Global warming
Time limit2sMemory limit512 MB
Choose one contiguous interval and a shift d with |d| <= x, then find the maximum possible length of a strictly increasing subsequence of the modified sequence.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Binary search, Segment tree, Greedy
- Solved
- No attempts yet
Problem
Global warming is an important issue and Johnny knows about it. He decided to analyze historical temperatures and find a subsequence of days (not necessarily consecutive) where the temperature was strictly increasing. That will convince the non-believers!
Johnny has found historical data from consecutive days. The temperature on the -th day was .
Formally, we are interested in finding the length of the longest increasing subsequence (LIS) of , that is, the largest possible for which it is possible to choose an increasing sequence of indices such that .
Johnny wants to find a really long subsequence, and that is why he decided to cheat a bit. He will first choose a non-empty interval of days and an integer (), and he will increase the temperature on each of those days by . A small change like that probably will not be noticed by the community, while at the same time it should make the LIS longer. It is allowed to choose .
What is the largest possible length of the LIS after a change?
Input
The first line of the standard input contains two space-separated integers and (, ), the number of days and the limit for the absolute value of .
The second line contains integers () separated by spaces, the sequence of historical temperatures.
Output
Print one integer, the largest possible length of the LIS after a single change.