-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConcert_Tickets.cpp
More file actions
34 lines (32 loc) · 876 Bytes
/
Concert_Tickets.cpp
File metadata and controls
34 lines (32 loc) · 876 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <bits/stdc++.h>
using namespace std;
int32_t main() {
int n, m;
cin >> n >> m;
map<int, int> tickets;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
tickets[t]++;
}
for (int i = 0; i < m; i++) {
int customer_price;
cin >> customer_price;
if (tickets.size() == 0) {
cout << -1 << endl;
continue;
}
auto paid = tickets.lower_bound(customer_price);
if (paid == tickets.begin() && paid->first > customer_price)
cout << -1 << endl;
else {
if (paid == tickets.end() || paid->first > customer_price)
paid--;
cout << paid->first << endl;
tickets[paid->first]--;
if (tickets[paid->first] == 0)
tickets.erase(paid->first);
}
}
return 0;
}