結果

問題 No.615 集合に分けよう
ユーザー Tsukasa_TypeTsukasa_Type
提出日時 2018-02-15 18:20:46
言語 Java21
(openjdk 21)
結果
AC  
実行時間 556 ms / 2,000 ms
コード長 497 bytes
コンパイル時間 3,536 ms
コンパイル使用メモリ 72,072 KB
実行使用メモリ 62,924 KB
最終ジャッジ日時 2023-08-27 05:15:33
合計ジャッジ時間 14,752 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 126 ms
55,424 KB
testcase_01 AC 125 ms
55,852 KB
testcase_02 AC 126 ms
55,408 KB
testcase_03 AC 125 ms
55,960 KB
testcase_04 AC 125 ms
55,724 KB
testcase_05 AC 127 ms
55,984 KB
testcase_06 AC 126 ms
55,784 KB
testcase_07 AC 134 ms
55,988 KB
testcase_08 AC 135 ms
56,212 KB
testcase_09 AC 139 ms
55,404 KB
testcase_10 AC 133 ms
55,564 KB
testcase_11 AC 134 ms
55,656 KB
testcase_12 AC 136 ms
56,192 KB
testcase_13 AC 186 ms
56,108 KB
testcase_14 AC 199 ms
55,904 KB
testcase_15 AC 293 ms
60,848 KB
testcase_16 AC 541 ms
60,728 KB
testcase_17 AC 523 ms
60,732 KB
testcase_18 AC 528 ms
61,160 KB
testcase_19 AC 529 ms
60,756 KB
testcase_20 AC 522 ms
60,276 KB
testcase_21 AC 537 ms
60,608 KB
testcase_22 AC 556 ms
60,896 KB
testcase_23 AC 413 ms
62,924 KB
testcase_24 AC 524 ms
60,580 KB
testcase_25 AC 123 ms
56,216 KB
testcase_26 AC 121 ms
56,256 KB
testcase_27 AC 374 ms
60,272 KB
testcase_28 AC 375 ms
60,260 KB
testcase_29 AC 482 ms
60,644 KB
testcase_30 AC 482 ms
60,844 KB
権限があれば一括ダウンロードができます

ソースコード

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