HDU 3530 Subsqueue ( 单调队列

Subsqueue

题目描述

There is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum element of the subsequence is no smaller than m and no larger than k.

输入

There are multiple test cases.
For each test case, the first line has three integers, n, m and k. n is the length of the sequence and is in the range [1, 100000]. m and k are in the range [0, 1000000]. The second line has n integers, which are all in the range [0, 1000000].
Proceed to the end of file.

输出

For each test case, print the length of the subsequence on a single line.

样例

Sample Input
5 0 0
1 1 1 1 1
5 0 3
1 2 3 4 5


Sample Output
5
4

题意

求一个数列中最大最小值差值在[m,k]之间 最大的范围
思路: 维护两个单调队列(一个递增一个递减)

AC代码

猜你喜欢

转载自blog.csdn.net/wang2332/article/details/80319460