Loading...
Loading...
Loading...
A coaching centre has the scores of n students in no particular order. Parents ask q questions. Each question gives a value x and asks how many students scored strictly less than x.
Answer every question.
Example
Input
6 3 72 45 90 45 60 88 60 45 100
Output
2 0 6
45, 45 are below 60. Nothing is below 45. All six are below 100.
Try the problem first. Open one hint at a time.
Checking every score for every question is n × q steps, up to 10^10. That is too slow.
Sort the scores once. Then all scores below x come first.
For each question, find the first index whose score is at least x. That index is the count.
Collect the answers in a StringBuilder and print once.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor