Problem P05. [算法课分治] 寻找第 k 个最大元素
先
sort
进行排序,然后输出第k大的元素即可
#include<iostream>
#include<bits/stdc++.h>
#include<cstdio>
using namespace std;
int n, k;
int arr[10005];
int main()
{
scanf("%d %d", &n, &k);
for (int i = 0; i < n; i++){
scanf("%d", &arr[i]);
}
sort(arr, arr+n);
printf("%d", arr[n-k]);
return 0;
}