求M≤m×p最大长度M-m
1. 原文
Given a sequence of positive integers and another positive integer p. The sequence is said to be a perfect sequence if M≤m×p where M and m are the maximum and minimum numbers in the sequence, respectively.
Now given a sequence and a parameter p, you are supposed to find from the sequence as many numbers as possible to form a perfect subsequence.
Input Specification:
Each input file contains one test case. For each case, the first line contains two positive integers N and p, where N (≤105) is the number of integers in the sequence, and p (≤109) is the parameter. In the second line there are N positive integers, each is no greater than 109.
output Specification:
For each test case, print in one line the maximum number of integers that can be chosen to form a perfect subsequence.
Sample Input:
1 | 10 8 |
Sample output:
1 | 8 |
2. 解析
求M≤m×p M-m最大
数组排序,对于每个当前i 查找满足num[i]*p>=num[j]的最大j,j不回溯。记录最大j-i
3. AC代码
1 |
|