#K15271. Keyword Rank

    ID: 24320 Type: Default 1000ms 256MiB

Keyword Rank

Keyword Rank

In this problem, you are given a list of keyword search frequencies and a list of query frequencies. Your task is to determine the rank of each query frequency among the keywords.

The rank is defined as follows: first, sort the given frequencies in non‐increasing order (i.e., descending order). For each unique frequency, assign a rank starting from 1, where the highest frequency gets rank 1. For a query frequency:

  • If the frequency is present in the list, output its assigned rank.
  • If the frequency is not present, output n+1, where n is the number of keywords.

For example, if the frequencies are: [100, 150, 150, 100, 200, 300] and the query is 100, the rank will be 5 because when sorted the unique frequencies and their ranks will be as follows:
300 → rank 1
200 → rank 2
150 → rank 3
100 → rank 5

You need to read the input from standard input (stdin) and output the result to standard output (stdout).

inputFormat

The input consists of three lines:

  • The first line contains two integers n and m, where n is the number of keywords and m is the number of queries.
  • The second line consists of n space-separated integers representing the keyword frequencies.
  • The third line consists of m space-separated integers representing the query frequencies.

outputFormat

Output a single line with m space-separated integers where each integer is the rank corresponding to the query frequency according to the criteria described.

## sample
6 3
100 150 150 100 200 300
100 300 50
5 1 7