PAT乙题 1030. 完美数列(25)

2018/01/26 PAT 共 560 字,约 2 分钟
//cpp:
#include <iostream>
#include <algorithm>
#include<math.h>
#include<string>
#include<vector>
#include<ctype.h>
#include<set>
using namespace std;
int main() {
#ifdef LOCAL
	freopen("D:\\datain.txt", "r", stdin);
#endif
	int n, p;
	cin >> n >> p;
	long long d[100005];
	for (int i = 0; i < n; i++) {
		scanf("%lld", &d[i]);
	}
	sort(begin(d), begin(d) + n);
	int maxc = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + maxc; j < n; j++) {
			if (d[j] <= d[i] * p) {
				int t = j - i + 1;
				if (t > maxc)
					maxc = t;
			}
			else
				break;
		}
	}
	cout << maxc;
	return 0;
}

Search

    Table of Contents