문제
제한 사항
입출력 예
풀이
let input = require('fs').readFileSync('/dev/stdin').toString().trim().split('\n');
let [n,m] = [...input.shift().split(" ").map(e => +e)]
let arr = input.shift().split(" ").map(e => +e);
const solution = (arr, m) => {
arr.sort((a, b) => a - b);
let answer = new Set();
let tmp = [];
const dfs = (index, cnt) => {
if (cnt === m) {
answer.add(tmp.join(" "));
} else {
for (let i = index; i < arr.length; i++) {
tmp.push(arr[i]);
dfs(i, tmp.length);
tmp.pop();
}
}
};
dfs(0, 0);
return [...answer].join("\n");
};
console.log(solution(arr, m));