简单,两次排序
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
32
33
34
35
36
37
38
39
40
41
42
|
#include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX 50000 struct
Vote {
int
index;
int
a;
int
b;
}; struct
Vote candidates[MAX];
int
N, K;
int
cmp_1( const
void
* a, const
void
* b) {
return
(( struct
Vote *)b)->a - (( struct
Vote *)a)->a;
} int
cmp_2( const
void
* a, const
void
* b) {
return
(( struct
Vote *)b)->b - (( struct
Vote *)a)->b;
} int
pick() {
qsort (candidates, N, sizeof (candidates[0]), cmp_1);
qsort (candidates, K, sizeof (candidates[0]), cmp_2);
return
candidates[0].index;
} int
main() {
int
i;
int
res;
scanf ( "%d%d" , &N, &K);
for (i = 0; i < N; i++) {
scanf ( "%d%d" , &candidates[i].a, &candidates[i].b);
candidates[i].index = i + 1;
}
res = pick();
printf ( "%d\n" , res);
return
0;
} |