略
import java.util.*;
public class Main {
private static final int N = 210;
private static int M, S, C;
private static int[] a, b;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
M = sc.nextInt();
S = sc.nextInt();
C = sc.nextInt();
a = new int[C];
for (int i = 0; i < C; i++) {
a[i] = sc.nextInt();
}
Arrays.sort(a);
int res = a[C - 1] - a[0] + 1;
b = new int[C - 1];
for (int i = 0; i + 1 < C; i++) {
b[i] = a[i + 1] - a[i] - 1;
}
Arrays.sort(b);
for (int i = 0; i <= (C - 1) / 2; i++) {
int temp = b[i];
b[i] = b[C - i - 2];
b[C - i - 2] = temp;
}
for (int i = 0; i < M - 1 && i < C - 1; i++) {
res -= b[i];
}
System.out.println(res);
}
}
标签:1349,三十二,int,private,nextInt,static,sc,贪心
From: https://www.cnblogs.com/he0707/p/18132045/lanqiaobei32