結果

問題 No.615 集合に分けよう
ユーザー Tsukasa_Type
提出日時 2018-02-15 18:20:46
言語 Java
(openjdk 23)
結果
AC  
実行時間 785 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 3,132 ms
コンパイル使用メモリ 75,104 KB
実行使用メモリ 49,308 KB
最終ジャッジ日時 2024-12-26 14:18:16
合計ジャッジ時間 17,573 ms
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 5
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int k = sc.nextInt();
		long[] ar = new long[n];
		long[] dif = new long[n-1];
		for (int i=0; i<n; i++) {
			ar[i] = sc.nextLong();
		}
		Arrays.sort(ar);
		for (int i=0; i<n-1; i++) {
			dif[i] = ar[i+1]-ar[i];
		}
		Arrays.sort(dif);
		long total = 0;
		for (int i=0; i<n-k; i++) {
			total += dif[i];
		}
		System.out.println(total);
	}
}
0