ГлавнаяСборникиТурнирыРазделыФорумыУчастникиПечатьПомощьО системе

Сборники > Алгоритмы и Структуры Данных > задача:


33. Concert Tickets

Задачи сборника

• 25. Josephus Queries
• 26. Exponentiation
• 27. Dice Combinations
• 28. Minimizing Coins
• 29. Coin Combinations I
• 30. Distinct Numbers
• 31. Apartments
• 32. Ferris Wheel
• 33. Concert Tickets
• 34. Maximum Subarray Sum
• 35. Stick Lengths
• 36. Missing Coin Sum
• 37. Collecting Numbers
• 38. Playlist
• 39. Towers
• 40. Traffic Lights
• 41. Finding Borders

Обратная связь

Если у вас есть предложения или пожелания по работе Contester, посетите форум сайта www.contester.ru.

Лимит времени 6000/6000/6000/6000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Сложность Альфа

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 h1,h2,…,hn : the price of each ticket. The last line contains m integers t1,t2,…,tm : 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≤n,m≤2⋅105
  • 1≤h(i),t(i)≤109

Example
Input:
5 3
5 3 7 8 5
4 8 3

Output:
3
8
-1

Для отправки решений необходимо выполнить вход.

www.contester.ru