import java.util.Arrays;
//array의 길이는 1 이상 100 이하입니다.
//array의 각 원소는 1 이상 100 이하입니다.
//commands의 길이는 1 이상 50 이하입니다.
//commands의 각 원소는 길이가 3입니다.[0][0]
//[1, 5, 2, 6, 3, 7, 4]를 2번째부터 5번째까지 자른 후 정렬합니다. [2, 3, 5, 6]의 세 번째 숫자는 5입니다.
// 0 1 2 3 4 5 6
// 여기 여기
//2-1 부터 5-1번 인덱스까지 출력
//다른 배열에 따로 저장
//정렬
// 리턴
public class Solution {
public int[] solution(int[] array, int[][] commands) {
int[] answer = {};
int[] a = {};
int q = 0;
for(int i = 0;i<commands.length-1;i++) {
for(int j = commands[i][0]-1;j<commands[i][1];j++) {//commands[i][0]째부터 commands[i][1]째까지 짤라서 a배열에 초기화
a[q] = array[j];
q++;
}
Arrays.sort(a);
answer[i] = a[commands[i][2]-1];
}
return answer;
}
}