hiho week 37 register

Ended

Participants:317

Verdict:Accepted
Score:100 / 100
Submitted:2015-03-15 09:48:59

Lang:GCC

Edit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <stdio.h>
int a[1000100];
int qsort(int l, int r, int k) {
    int first, last, key;
    first = l; last = r;
    key = a[last];
    while (first < last) {
        while (first<last && a[first]<=key) first++;
        a[last] = a[first];
        while (first<last && a[last]>=key) last--;
        a[first] = a[last];
    }
    a[first] = key;
    if (first == k) return a[first];
    if (l <= first-1 && first > k) return qsort(l, first-1, k);
    if (r >= first+1 && first < k) return qsort(first+1, r, k);
    return -1;
}
int main(int argc, char* argv[]) {
    int N, k;
    scanf("%d%d", &N, &k);
    int i;
    for (i=0; i<N; i++) scanf("%d", a+i);
    k--;
    if (k<0 || k>=N) {
        printf("-1\n");
        return 0;
    }
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX