?1
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
long long p;
cin >> n >> p;
int arr[100000];
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n); // 递增
// 1 2 3 4 5 6 7 8 9 20
int count = 0;
for (int i = 0; i < n; i++)
{
long long cmp = arr[i] * p; //此次循环的比较项
if (n - i <= count)
break;
for (int j = i + count; j < n; j++)
{
if (arr[j] <= cmp)
{
count = max(count, j - i + 1);
}
else
break;
}
}
cout << count;
return 0;
}
2
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int n;
long long p;
cin >> n >> p;
int arr[100000];
for (int i = 0; i < n; i++)
cin >> arr[i];
sort(arr, arr + n);
// 1 2 3 4 5 6 7 8 9 20
int count = 0;
int j = 0;
for (int i = 0; i < n; i++)
{
long long cmp = arr[i] * p; //此次循环的比较项
if (n - i <= count)
break;
for (j; j < n; j++)
{
if (arr[j] <= cmp)
{
count = max(count, j - i + 1);
}
else
break;
}
}
cout << count;
return 0;
}
|