Note
-
for循环嵌套二分查找!!!
-
“maximum number of integers that can be chosen to form a perfect subsequence”
可以选择组成一个完美子序列的最大整数;是序列长度!!!不是序列中的最大数
-
不是从a[0]开始的序列就一定最长!!!不要想当然了…
Code:
#include<bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
freopen("data.txt","r",stdin);
#endif
int n;
long long p;
scanf("%d%lld",&n,&p);
int a[n];
for(int i=0;i<n;i++)
scanf("%d",&a[i]);
sort(a,a+n);
int ans=0,left,right,mid;
long long min;
for(int i=0;i<n;i++){
min=(long long)a[i]*p;
left=i+1,right=n-1; //left从i+1开始!
if(a[n-1]<=min) ans=max(ans,n-i); //here!
else{
while(left<right){
mid=(left+right)/2;
if(a[mid]>min)
right=mid;
else
left=mid+1;
}
ans=max(ans,left-i);
}
}
cout<<ans;
return 0;
}