fork download
  1. n,m = map(int,input().split())
  2. num = list(map(int,input().split()))
  3. num.sort()
  4. check = [False]*n
  5. ans = [0]*m
  6. tmp = []
  7. def go(index, n, m):
  8. if index == m:
  9. tmp.append(" ".join(map(str,ans)))
  10. return
  11.  
  12. for i in range(n):
  13. if check[i]:
  14. continue
  15. check[i] = True
  16. ans[index] = num[i]
  17. go(index+1, n, m)
  18. check[i] = False
  19.  
  20. go(0,n,m)
  21. tmp = list(set(tmp))
  22. tmp.sort()
  23.  
  24. for i in tmp:
  25. print(i)
Success #stdin #stdout 0.03s 9816KB
stdin
2 2
11 9
stdout
11 9
9 11