hiho week 37 register

Ended

Participants:317

Verdict:Accepted
Score:100 / 100
Submitted:2015-03-14 21:05:48

Lang:G++

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <bits/stdc++.h>
#define sc scanf
#define pf printf
using namespace std;
int main()
{
    int a[100000], n, k;
    while( ~sc("%d%d", &n, &k) )
    {
        k--;
        for(int i=0; i<n; i++) sc("%d", &a[i]);
        if( k<0 || k>=n ) k = -1;
        else nth_element( a, a+k, a+n);
        pf("%d\n", k==-1?-1:a[k]);
    }
}
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX