1030. 完美数列

题目在这里


p的值要用long long型的,否则结果会溢出。


#include <iostream>
#include <bits/stdc++.h>
using namespace std;

int main()
{
	long long n, p;
	cin >> n >> p;
	int a[100001];
	for(int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a, a + n);
	int count = 0;
	for(int i = 0; i < n; i++) {
		for(int j = i + count - 1; j < n; j++) {
			if(a[i] * p < a[j]) {
				break;
			}
			if(j - i + 1 > count) {
				count = j - i + 1;	
			}
			
        }
    }
	cout << count;
	return 0;
}


猜你喜欢

转载自blog.csdn.net/qq_39227338/article/details/80183327