link: https://cses.fi/problemset/task/1091
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,…,h_n: the price of each ticket.
The last line contains m integers t_1,t_2,…,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 less than or equal to n, m less than or equal to 2 times 10^5
1 less than or equal to h_i, t_i less than or equal to 10^9
Example
Input:
5 3
5 3 7 8 5
4 8 3
Output:
3
8
My attempt so far:
#include <iostream>
#include <set>
int main()
{
int n;
int m;
std::cin >> n;
std::cin >> m;
std::multiset<int> price;
std::multiset<int> max;
int input;
for (int i = 0; i < n; i++)
{
std::cin >> input;
price.insert(input);
}
for (int i = 0; i < m; i++)
{
std::cin >> input;
max.insert(input);
}
return 0;
}
So far, I have figured out how to read the input and store them indisde multisets, but I do not know how to continue 🙁 Any suggestions?
Jekyll is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.