import java.util.*;
import java.io.*;

public class Main {
    public static int[] numbers;
    public static int[] ans;
    public static StringBuilder sb;
    
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] arr1 = br.readLine().split(" ");
        String[] arr2 = br.readLine().split(" ");
        int n = Integer.parseInt(arr1[0]); int m = Integer.parseInt(arr1[1]);
        numbers = new int[n]; ans = new int[m];
        sb = new StringBuilder();
        
        for(int i=0; i<n; i++) { numbers[i] = Integer.parseInt(arr2[i]); }
        
        Arrays.sort(numbers);
        calc(0, 0, n, m);
        
        System.out.println(sb);
    }
    
    public static void calc(int index, int selected, int n, int m) {
        if(selected==m) {
            for(int a : ans) { sb.append(String.valueOf(a)).append(" "); }
            
            sb.append("\n"); return;
        }
        
        if(index>=n) { return; }
        
        ans[selected] = numbers[index];
        calc(index+1, selected+1, n, m);
        calc(index+1, selected, n, m);
    }
}

'Problem Solving > BOJ' 카테고리의 다른 글

[Silver 3] 15657번 N과 M (8)  (0) 2022.04.01
[Silver 3] 15656번 N과 M (7)  (0) 2022.04.01
[Silver 3] 15654번 N과 M (5)  (0) 2022.04.01
[Silver 3] 15652번 N과 M (4)  (0) 2022.04.01
[Silver 3] 15651번 N과 M (3)  (0) 2022.04.01