AcWing——1571. 完美序列
双指针解法
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 100000+10;
ll a[N];
int main() {
ios::sync_with_stdio(0), cout.tie(0), cin.tie(0);
int n, p, ans = 0;
cin >> n >> p;
for(int i = 0; i < n; ++i) cin >> a[i];
sort(a, a+n);
for(int i = 0, j = 0; i < n; i++){
while(j < n && a[i] > a[j] * p) j++;
ans = max(ans, i - j + 1);
}
cout << ans;
return 0;
}