pat-B-1030. Perfect Series (25)

Source: Internet
Author: User

1030. Perfect Sequence (25) time limit MS Memory limit 65536 KB code length limit 8000 B procedure StandardAuthor Cao, Peng

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
Reminder: Do not say to the original sequence of the series, so you can first sort

1#include <bits/stdc++.h>2 using namespacestd;3 intMain ()4 {5   intn,maxx=0;6   Doublep,a[100010];7Cin>>n>>p;8    for(intI=0; i<n; i++)9Cin>>A[i];TenSort (a,a+n); One    for(intI=0; i<n; i++) A   { -      for(intj=i+maxx-1; j<n; J + +) -     { the       if(a[i]*p<A[j]) -          Break; -       if(j-i+1>Maxx) -maxx=j-i+1; +     } -   } +cout<<maxx<<Endl; A   return 0; at}

Pat-B-1030. Perfect sequence (+)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.