1085. Perfect Sequence (25)

#include <iostream>
#include <algorithm>

using namespace std;

long long num[100010];

int getindex(int low, int high, long long goal)
{
	int mid;
	while(low < high)
	{
		mid = (low + high) / 2;
		if(num[mid] > goal)
		{
			high = mid;
		}
		else
		{
			low = mid + 1;
		}
	}

	return high;
}

int main()
{
	int n;
	long long p;
	scanf("%d%lld", &n, &p);

	int i;
	for(i = 1; i <= n; i++)
	{
		scanf("%lld", &num[i]);
	}

	sort(num + 1, num + n + 1);

	int count, res = 0, index;
	for(i = 1; i <= n; i++)
	{
		if(n - i + 1 <= res)
		{
			break;
		}

		index = getindex(1, n + 1, p * num[i]);
		count = index - i;

		if(count > res)
		{
			res = count;
		}
	}

	printf("%d\n", res);

	system("pause");
	return 0;
}

 

posted on 2025-11-23 17:19  王景迁  阅读(3)  评论(0)    收藏  举报

导航