C - Monotonically Increasing Editorial by cai_lw
You can simply use the combinations
function in Python’s standard library, which outputs all N-element subsets of a M-element set, in lexicographical order.
from itertools import combinations
n, m = list(map(int, input().split()))
for l in combinations(range(1, m + 1), n):
print(*l, sep=' ')
posted:
last update: