N girls
Practice
2.4 (14 votes)
Algorithms
Binary search
Easy
Searching
Problem
89% Success 2161 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given \(n\) boxes and the size of the \(i^{th}\) box is \(a_i\) . You can select at most \(k\) boxes and change their size to a positive integer.

Select some boxes and paint it with the Red color. These boxes must satisfy the following condition:

  • There must be no \(1\leq i,\ j\leq n\) such that both \(i,\ j\) boxes are red and \(\frac{a_i}{a_j} > \frac{P}{Q}\).

Determine the maximum number of boxes that you can color in Red.

Input format

  • First line: Four integers \(n,\ k ,\ P ,\ and\ Q\ (1\leq k \leq n \leq 2 * 10^5,\ 1\leq Q \leq P \leq 10^9)\)
  • Second line: Sequence \(a_1,...,a_n\ (1\leq a_i \leq 10^9)\)

Output format

Print the required in a single line. The output must be an integer and display the maximum number of boxes that you can color in Red.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
55 votes
Tags:
ApprovedBinary SearchEasyGreedy AlgorithmsReadySorting
Points:30
54 votes
Tags:
AlgorithmsBinary SearchC++
Points:30
49 votes
Tags:
AlgorithmsApprovedBinary SearchEasySearching