解题代码
#include<cstdio>
#include<algorithm>
using namespace std;
const int nmax = 100010;
int a[nmax], n, p, cnt;
int main() {
scanf("%d%d", &n, &p);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; i++) {
int j = upper_bound(a + i + 1, a + n, (long long)p*a[i]) - a;
if (j - i > cnt) cnt = j - i;
}
printf("%d", cnt);
return 0;
}
测试结果
问题整理
1.二分法。