본문 바로가기

알고리즘/프로그래머스 문제풀이

[프로그래머스] 정렬 / k번째 수

#include <string>
#include <vector>
#include<algorithm>

using namespace std;

vector<int> solution(vector<int> array, vector<vector<int>> commands) {
    vector<int> answer;
    for(vector<int> elem : commands) {
        vector<int> temp;
        temp.assign(array.begin() + elem[0] - 1, array.begin() + elem[1]);
        sort(temp.begin(), temp.end());
        answer.push_back(temp[elem[2]-1]);
    }
    return answer;
}