LCC '24 Contest 2 S1 - Betting Odds

View as PDF

Submit solution


Points: 3 (partial)
Time limit: 1.0s
Java 8 1.5s
Python 3 1.5s
Memory limit: 256M

Author:
Problem type

There are N contestants remaining, each with a unique cyan jersey numbered with n_i (0\le n_i \le 10^9). The contestants are ordered in single file from least to greatest number n_i.

In front of the first contestant is a glass bridge that may break as they cross.

As a rich VIP, you've bet on P (1 \le P \le N) players each with numbers p_i (0\le p_i<10^9). For each of your contestants, you'd like to know how many people are in front of them in the line in order to gauge how likely they are to survive.

Input Specification

The first line of input contains two integers, N and P, the number of contestants and the number of contestants you're betting on respectively.

The next N lines of input each contain a number n_i, the numbers on each contestant's jersey, sorted from least to greatest.

The next P lines of input each contain a number p_i, the numbers of each contestant's jersey that you're betting on.

Output Specification

Output P lines, each line containing the number of contestants ahead of contestant p_i in the order that they were inputted.

If the contestant p_i doesn't exist, output -1

Constraints

Subtask 1

1\le N \le 1000

Subtask 2

1\le N \le 10^5

Sample Input 1

5 3
3
7
15
24
33
15
8
7

Sample Output 1

2
-1
1

Comments

There are no comments at the moment.