#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN = 100010;
int n, p, a[MAXN];
int binarySearch(int i, long long x){
if(a[n - 1] <= x) //如果最大的数比x小,则返回n
return n;
int left = i + 1;
int right = n - 1; //在区间[i+1, n-1]内查找
int mid;
while(left < right){
mid = (left + right) / 2;
if(a[mid] <= x) //若区间中间的数小于x,则这个数在mid后面
left = mid + 1;//左端点记为mid+1
else //若区间中间的数大于x,则这个数在mid前面
right = mid; //右端点记为mid
}
return left;
}
int main(){
scanf("%d %d", &n, &p);
for(int i = 0; i < n; i++){
scanf("%d", &a[i]);
}
sort(a, a + n);//不加cmp,默认从小到大
int count = 1;
for(int i = 0; i < n; i++){
int j = binarySearch(i, (long long)a[i] * p);
count = max(count, j - i);
}
printf("%d", count);
return 0;
}
原文地址:https://www.cnblogs.com/zjsaipplp/p/10425232.html
时间: 2024-11-09 04:15:50