zl程序教程

您现在的位置是:首页 >  其它

当前栏目

1085 Perfect Sequence (25 分)【简单 / 双指针】

简单 指针 25 sequence perfect
2023-09-11 14:15:52 时间

在这里插入图片描述
https://pintia.cn/problem-sets/994805342720868352/problems/994805381845336064

#include<bits/stdc++.h>
using namespace std;
typedef long long int LL;
const int N=1e5*2+10;
LL a[N],n,p;
int main(void)
{
    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(j<n&&a[j]*p<a[i]) j++;
        ans=max(ans,i-j+1);
    }
    cout<<ans<<endl;
}