about summary refs log tree commit diff
path: root/codechef/dpairs.py
blob: 5110410c85512ea0484ea8c96a883aa116a54b1d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#!/usr/bin/env python3
from bisect import bisect_left as bsearch

input()
X, A = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))
Y, B = zip(*sorted(enumerate(map(int, input().split())), key=lambda t: t[1]))

N, M = len(A), len(B)
i = j = 0
for _ in range(N + M - 1):
    print(X[i], Y[j])
    try:
        if A[i + 1] < B[j + 1]: i += 1
        else: j += 1
    except IndexError:
        if i + 1 < N: i += 1
        else: j += 1