PAT 1085. 完美序列
原题链接
简单
作者:
YAX_AC
,
2024-11-20 21:03:08
,
所有人可见
,
阅读 5
//a sequence of positive正整数序列 positive integer正整数
//you are supposed to find from
//the sequence as many numbers as possible to form a perfect subsequence.
//你应该从序列中找到尽可能多的数字以构成一个完美的子序列。
//双指针
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
const int N = 100010;
int n,p;
int a[N];
int main()
{
cin>>n>>p;
for(int i = 0; i<n; i++) cin>>a[i];
sort(a,a+n);
int res = 0;
for(int i = 0,j = 0; i<n; i++)
{
while((long long)a[j]*p<a[i]) j++;
res = max(res,i-j+1);
}
cout<<res;
return 0;
}