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

Bài tập thuộc lộ trình

2 lộ trình

Vé hòa nhạc (Concert Tickets)

Concert Tickets

Source: CSES

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn concert tickets, with ticket ii priced at hih_i. Then mm customers arrive sequentially. Customer jj is willing to pay at most tjt_j. 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 −1-1 when no suitable ticket remains.

Input

  • Line 1 contains integers n,mn,m, the ticket and customer counts.
  • Line 2 contains exactly nn integers h1,h2,…,hnh_1,h_2,\ldots,h_n, the ticket prices.
  • Line 3 contains exactly mm integers t1,t2,…,tmt_1,t_2,\ldots,t_m, customers' maximum prices in arrival order.

Output

Print mm lines; line jj is the price paid by customer jj, or -1 if no ticket is sold.

Subtasks

  • Subtask 1 (20 points): 1≤n≤201\le n\le 20; 1≤m≤201\le m\le 20; 1≤hi,tj≤1091\le h_i,t_j\le 10^9 for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤m≤20001\le m\le 2000; 1≤hi,tj≤1091\le h_i,t_j\le 10^9 for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.
  • Subtask 3 (50 points): 1≤n≤2000001\le n\le 200000; 1≤m≤2000001\le m\le 200000; 1≤hi,tj≤1091\le h_i,t_j\le 10^9 for all 1≤i≤n1\le i\le n, 1≤j≤m1\le j\le m.

Examples

Input

5 3
5 3 7 8 5
4 8 3

Output

3
8
-1

Explanation

Customer 1 can pay at most 44 and purchases the ticket priced 33. Customer 2 can pay 88 and receives the ticket priced 88; the remaining tickets cost 5,5,75,5,7. Customer 3 can pay at most 33, but the 33 ticket is already sold, so the output is -1.