-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconcert_tickets.py
More file actions
47 lines (36 loc) · 1 KB
/
concert_tickets.py
File metadata and controls
47 lines (36 loc) · 1 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
# =======================
# Python CP Template
# (bits/stdc++.h equivalent)
# =======================
import sys
# Fast I/O
input = sys.stdin.readline
# Common imports
from collections import defaultdict, deque, Counter
from itertools import combinations, permutations, product, accumulate
from functools import lru_cache, reduce
import heapq
import bisect
# Constants
INF = float('inf')
MOD = 10**9 + 7
def solve():
n, m = map(int, input().split())
tickets = list(map(int, input().split()))
customers = list(map(int, input().split()))
tickets.sort() # sort ticket prices
ans = []
for t in customers:
# index of first element > t
idx = bisect.bisect_right(tickets, t) - 1
if idx >= 0:
ans.append(str(tickets[idx]))
tickets.pop(idx) # remove used ticket
else:
ans.append("-1")
sys.stdout.write("\n".join(ans))
# =======================
# Entry Point
# =======================
if __name__ == "__main__":
solve()