CSES - Concert Tickets
Xem dạng PDF
Gửi bài giải
Điểm:
1,00 (OI)
Giới hạn thời gian:
1.0s
Giới hạn bộ nhớ:
512M
Input:
stdin
Output:
stdout
Nguồn bài:
Dạng bài
Ngôn ngữ cho phép
C, C++, Java, Kotlin, Pascal, PyPy, Python, Scratch
There are ~n~ concert tickets available, each with a certain price. Then, ~m~ 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 ~n~ and ~m~: the number of tickets and the number of customers.
The next line contains ~n~ integers ~h\_1,h\_2,\ldots,h\_n~: the price of each ticket.
The last line contains ~m~ integers ~t\_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~.
Constraints
- ~1 \le n, m \le 2 \cdot 10^5~
- ~1 \le h\_i, t\_i \le 10^9~
Example Input
5 3
5 3 7 8 5
4 8 3
Example Output
3
8
-1
Bình luận