-
Notifications
You must be signed in to change notification settings - Fork 129
/
Copy path1030. 完美数列.cpp
44 lines (44 loc) · 979 Bytes
/
1030. 完美数列.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
//二分查找
#include <bits/stdc++.h>
using namespace std;
using gg = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
gg ni, pi, ans = 0;
cin >> ni >> pi;
vector<gg> v(ni);
for (gg i = 0; i < ni; ++i) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (gg i = 0; i < ni; ++i) {
ans = max(ans,
upper_bound(v.begin(), v.end(), v[i] * pi) - v.begin() - i);
}
cout << ans;
return 0;
}
// two pointers
#include <bits/stdc++.h>
using namespace std;
using gg = long long;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
gg ni, pi, ans = 0;
cin >> ni >> pi;
vector<gg> v(ni);
for (gg i = 0; i < ni; ++i) {
cin >> v[i];
}
sort(v.begin(), v.end());
for (gg i = 0, j = 0; j < v.size(); ++i) {
while (j < v.size() and v[j] <= v[i] * pi) {
++j;
}
ans = max(ans, j - i);
}
cout << ans;
return 0;
}