boj - 11004 K번째 수 (자바)

SlowAnd·2023년 12월 31일
0

https://www.acmicpc.net/problem/11004

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;


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

        int targetIndex = Integer.parseInt(r.readLine().split(" ")[1]);
        int target = Arrays.stream(r.readLine().split(" ")).mapToInt(x -> Integer.parseInt(x))
                .sorted()
                .skip(targetIndex-1)
                .findFirst()
                .getAsInt();
        w.write(target+"");
        w.flush();
    }
}

0개의 댓글