Study/Baekjoon

[백준/C++] 25305 커트라인

에린_1 2024. 2. 22. 20:01
728x90

25305 커트라인

#include <bits/stdc++.h>
using namespace std;

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	vector<int> num_arr;
	int n, k;
	cin >> n >> k;
	for (int i = 0; i < n; ++i)
	{
		int tmp;
		cin >> tmp;
		num_arr.push_back(tmp);
	}
	sort(num_arr.begin(), num_arr.end(),greater<int>());
	cout << num_arr[k - 1];
	return 0;
}

  • sort 정렬로 쉽게 풀 수 있는 문제
  • greater<void>() 를 쓰면 내림차순으로 정렬할 수 있다.
728x90

'Study > Baekjoon' 카테고리의 다른 글

[백준/C++] 10773 제로  (0) 2024.02.23
[백준/C++] 18870 좌표 압축  (1) 2024.02.22
[백준/C++] 2587 대표값2  (0) 2024.02.22
[백준/C++] 10814 나이순 정렬  (0) 2024.02.21
[백준/C++] 11650 좌표 정렬하기2  (0) 2024.02.21