結果

問題 No.615 集合に分けよう
ユーザー Mcpu3Mcpu3
提出日時 2018-11-30 22:59:14
言語 Java21
(openjdk 21)
結果
AC  
実行時間 546 ms / 2,000 ms
コード長 506 bytes
コンパイル時間 3,406 ms
コンパイル使用メモリ 71,776 KB
実行使用メモリ 61,052 KB
最終ジャッジ日時 2023-09-09 06:36:33
合計ジャッジ時間 13,802 ms
ジャッジサーバーID
(参考情報)
judge12 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 123 ms
55,804 KB
testcase_01 AC 124 ms
55,928 KB
testcase_02 AC 123 ms
56,132 KB
testcase_03 AC 123 ms
55,932 KB
testcase_04 AC 123 ms
55,608 KB
testcase_05 AC 123 ms
56,192 KB
testcase_06 AC 124 ms
55,980 KB
testcase_07 AC 133 ms
56,080 KB
testcase_08 AC 132 ms
54,448 KB
testcase_09 AC 134 ms
56,048 KB
testcase_10 AC 130 ms
56,280 KB
testcase_11 AC 131 ms
55,960 KB
testcase_12 AC 134 ms
56,144 KB
testcase_13 AC 179 ms
56,164 KB
testcase_14 AC 194 ms
54,408 KB
testcase_15 AC 305 ms
60,456 KB
testcase_16 AC 517 ms
60,608 KB
testcase_17 AC 546 ms
60,816 KB
testcase_18 AC 512 ms
60,832 KB
testcase_19 AC 509 ms
60,384 KB
testcase_20 AC 529 ms
60,664 KB
testcase_21 AC 530 ms
60,712 KB
testcase_22 AC 543 ms
60,496 KB
testcase_23 AC 405 ms
60,212 KB
testcase_24 AC 521 ms
60,788 KB
testcase_25 AC 123 ms
55,920 KB
testcase_26 AC 122 ms
55,792 KB
testcase_27 AC 367 ms
60,380 KB
testcase_28 AC 355 ms
60,364 KB
testcase_29 AC 481 ms
60,780 KB
testcase_30 AC 476 ms
61,052 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.Arrays;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt(), K = sc.nextInt();
		long a[] = new long[N], ans = 0, tmp[] = new long[N - 1];
		for (int i = 0; i < N; ++i) a[i] = sc.nextLong();
		sc.close();
		Arrays.sort(a);
		for (int i = 0; i < N - 1; ++i) tmp[i] = a[i + 1] - a[i];
		Arrays.sort(tmp);
		for (int i = 0; i < N - K; ++i) ans += tmp[i];
		System.out.print(ans);
	}
}
0