Account
GitHubFeedback
Drafts and results saved on this device
Submit on CSES.fi
CSES Problemset/Sorting and Searching

Concert Tickets

#1091
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

Time limit:1.00 s
Memory limit:512 MB
Unsolved
Download Tests (.zip)

There are nn concert tickets available, each with a certain price. Then, mm customers arrive, one after another.

Each customer announces the maximum price they are willing to pay for a ticket, and after this, they will get a ticket with the nearest possible price such that it does not exceed the maximum price.

Input

The first input line contains integers nn and mm: the number of tickets and the number of customers.

The next line contains nn integers h1,h2,…,hnh_1,h_2,\ldots,h_n: the price of each ticket.

The last line contains mm integers t1,t2,…,tmt_1,t_2,\ldots,t_m: the maximum price for each customer in the order they arrive.

Output

Print, for each customer, the price that they will pay for their ticket. After this, the ticket cannot be purchased again.

If a customer cannot get any ticket, print −1-1.

Constraints
  • 1≤n,m≤2⋅1051 \le n, m \le 2 \cdot 10^5
  • 1≤hi,ti≤1091 \le h_i, t_i \le 10^9
Sample Test Cases (1)
Example 1ID: sample-1
Input
5 3
5 3 7 8 5
4 8 3
Expected Output
3
8
-1
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|1 line, 0 chars
Test Bench
Download .zip
Input (stdin)
5 3
5 3 7 8 5
4 8 3
Expected Output
3
8
-1