4 21 21 32 23 4Example Output
3Hint
Author
lin
快速排序。。。。
01 | #include<stdio.h> |
02 | void dog( int a[], int l, int r); |
03 | int main() |
04 | { |
05 | int i, n, b, c, num, m, a[100000]; |
06 | while ( scanf ( "%d%d" , &n, &m) != EOF) |
07 | { |
08 | for (i = 0; i < n; i++) |
09 | { |
10 | scanf ( "%d%d" , &b, &c); |
11 | a[i] = c - b; |
12 | } |
13 | dog(a, 0, n - 1); |
14 | i = n - 1; |
15 | num = 0; |
16 | while (m > 0) |
17 | { |
18 | num += a[i]; |
19 | i--; |
20 | m--; |
21 | } |
22 | printf ( "%d/n" , num); |
23 | } |
24 | return 0; |
25 | } |
26 | void dog( int a[], int l, int r) |
27 | { |
28 | if (l < r) |
29 | { |
30 | int i = l, j = r, x = a[l]; |
31 | while (i < j) |
32 | { |
33 | while (i < j && a[j] >= x) |
34 | j--; |
35 | if (i < j) |
36 | a[i++] = a[j]; |
37 | while (i < j && a[i] < x) |
38 | i++; |
39 | if (i < j) |
40 | a[j--] = a[i]; |
41 | } |
42 | a[i] = x; |
43 | dog(a, l, i - 1); |
44 | dog(a, i + 1, r); |
45 | } |
46 | else return ; |
47 | } |
新闻热点
疑难解答