#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long int LL;
const int N=1e5+30;
LL a[N];
int main(void)
{
LL n,p,temp; cin>>n>>p;
for(int i=0;i<n;i++) cin>>a[i];
sort(a,a+n);
int ans=0;
for(int i=0,j=0;i<n;i++)
{
while(a[j]*p<a[i]) j++;//将不满足的剔除
ans=max(i-j+1,ans);//求最大的值
}
cout<<ans<<endl;
return 0;
}
【PAT乙级】1030 完美数列 (25 分)
最新推荐文章于 2022-10-17 20:23:20 发布
该博客探讨了一段C++代码,用于在已排序的整数数组中找到最大值,通过移动指针和比较来优化搜索过程。算法首先对数组进行排序,然后使用两个指针i和j,通过剔除小于当前元素p倍的元素来快速定位最大值,最终输出最大连续子数组长度。
摘要由CSDN通过智能技术生成