本题较简单,从小到大排序后,采用two pointer即可。
测试点5 个人感觉是个数据溢出测试点,即m * p 的值可能超出int 范围,因此需要在判断中转换一下,
AC代码:
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n,p;
cin >> n >>p;
vector<int>num(n);
for(int i = 0; i < n; i++)
scanf("%d",&num[i]);
sort(num.begin(),num.end());
int maxn = -1,index = 0,now = 0;
while(now < n)
{
if(num[now] <= (long long)num[index] * p)
{
maxn = max(maxn,now - index + 1);
now++;
}
else
index++;
}
cout<< maxn;
return 0;
}