PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#GD0000217. Vé hòa nhạc (Concert Tickets)
HỌC THEO LỘ TRÌNH
2 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Vé hòa nhạc (Concert Tickets)
Concert Tickets
Source: CSES
Version: Phuoc Hung OJ Extended
Problem Statement
There are concert tickets, with ticket priced at . Then customers arrive sequentially. Customer is willing to pay at most . Each customer must receive the most expensive remaining ticket not exceeding their limit. A sold ticket cannot be sold again. Print the price received by each customer, or when no suitable ticket remains.
Input
- Line 1 contains integers , the ticket and customer counts.
- Line 2 contains exactly integers , the ticket prices.
- Line 3 contains exactly integers , customers' maximum prices in arrival order.
Output
Print lines; line is the price paid by customer , or -1 if no ticket is sold.
Subtasks
- Subtask 1 (20 points): ; ; for all , .
- Subtask 2 (30 points): ; ; for all , .
- Subtask 3 (50 points): ; ; for all , .
Examples
Input
5 3
5 3 7 8 5
4 8 3
Output
3
8
-1
Explanation
Customer 1 can pay at most and purchases the ticket priced . Customer 2 can pay and receives the ticket priced ; the remaining tickets cost . Customer 3 can pay at most , but the ticket is already sold, so the output is -1.