๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Algorithm ๐Ÿง‘๐Ÿป‍๐Ÿ’ป/๋ฐฑ์ค€(BOJ)

[๋ฐฑ์ค€,c++] 11004๋ฒˆ - K๋ฒˆ์งธ ์ˆ˜

by dkswnkk 2021. 10. 26.
 

11004๋ฒˆ: K๋ฒˆ์งธ ์ˆ˜

์ˆ˜ N๊ฐœ A1, A2, ..., AN์ด ์ฃผ์–ด์ง„๋‹ค. A๋ฅผ ์˜ค๋ฆ„์ฐจ์ˆœ ์ •๋ ฌํ–ˆ์„ ๋•Œ, ์•ž์—์„œ๋ถ€ํ„ฐ K๋ฒˆ์งธ ์žˆ๋Š” ์ˆ˜๋ฅผ ๊ตฌํ•˜๋Š” ํ”„๋กœ๊ทธ๋žจ์„ ์ž‘์„ฑํ•˜์‹œ์˜ค.

www.acmicpc.net

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int N, A;
    cin >> N>>A;
    vector<long long int>v(N);

    for(int i=0; i<N; i++){
        long long int number;
        cin >> number;
        v[i] = number;

    }
    sort(v.begin(), v.end());

    cout << v[A-1];

}

๋Œ“๊ธ€