Given a positive integer sequence, and a positive integer p, the maximum value in this sequence is m, the minimum is m, and if M <= m * p, then this sequence is called the perfect sequence.
Now given the parameter p and some positive integers, you can choose as many numbers as possible to make a perfect sequence.
Input format:
Enter the first line to give two positive integers n and p, where N (<= 105) is the number of positive integers entered, and P (<= 109) is the given parameter. The second line gives n positive integers, each with a number not exceeding 109.
Output format:
You can select the maximum number of rows in a row to make a perfect sequence.
Input Sample:
10 82 3 20 4 5 1 6 7 8 9
Sample output:
8
In the beginning no Brain O (N2) timeout, and then optimize, J do not start from I, continue from the last place, because the array is already sorted. One less variable is correct, and there is no finding where the original mistake was.
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cctype>#include<cstdlib>#include<cmath>#include<string>#include<map>#include<Set>#include<queue>#include<vector>#include<stack>#include<cctype>using namespacestd;typedef unsignedLong Longull;#defineINF 0XFFFFFFFLong Longa[100000];intMain () {Long Longn,x,y,i,j,k; Memset (A,0,sizeof(a)); CIN>>x>>y; for(i=0; i<x;++i) Cin>>A[i]; Sort (A,a+x); K=1; J=0; for(i=0; i<x;++i) { while(a[j]<=a[i]*y&&j<x) {++J; } k=max (k,j-i); } cout<<k<<Endl; return 0;}
pat1030.--Perfect Series