boj-25305 커트라인(자바)

SlowAnd·2023년 12월 29일
0
package boj;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class boj_25305 {
    public static void main(String[] args) throws IOException {
        BufferedReader r = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter w = new BufferedWriter(new OutputStreamWriter(System.out));

        List<String> list = Arrays.stream(r.readLine().split(" ")).collect(Collectors.toList());
        int targetIndex = Integer.parseInt(list.get(1))-1;

        Integer targetNumber = Arrays.stream(r.readLine().split(" "))
                .map(Integer::parseInt)
                .sorted(Comparator.reverseOrder())
                .collect(Collectors.toList())
                .get(targetIndex);
        w.write(targetNumber.toString());
        w.flush();
    }
}

0개의 댓글