結果

問題 No.615 集合に分けよう
ユーザー htensaihtensai
提出日時 2019-11-14 14:18:44
言語 Java21
(openjdk 21)
結果
AC  
実行時間 560 ms / 2,000 ms
コード長 545 bytes
コンパイル時間 2,154 ms
コンパイル使用メモリ 74,720 KB
実行使用メモリ 62,748 KB
最終ジャッジ日時 2023-10-21 19:59:13
合計ジャッジ時間 12,785 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,412 KB
testcase_01 AC 134 ms
57,516 KB
testcase_02 AC 133 ms
57,632 KB
testcase_03 AC 131 ms
57,472 KB
testcase_04 AC 132 ms
57,428 KB
testcase_05 AC 131 ms
57,396 KB
testcase_06 AC 135 ms
57,656 KB
testcase_07 AC 143 ms
57,872 KB
testcase_08 AC 144 ms
57,724 KB
testcase_09 AC 144 ms
57,608 KB
testcase_10 AC 143 ms
57,688 KB
testcase_11 AC 145 ms
57,728 KB
testcase_12 AC 141 ms
57,740 KB
testcase_13 AC 183 ms
57,700 KB
testcase_14 AC 199 ms
57,720 KB
testcase_15 AC 307 ms
62,748 KB
testcase_16 AC 560 ms
62,232 KB
testcase_17 AC 519 ms
62,188 KB
testcase_18 AC 528 ms
62,260 KB
testcase_19 AC 507 ms
62,100 KB
testcase_20 AC 517 ms
62,428 KB
testcase_21 AC 492 ms
62,208 KB
testcase_22 AC 557 ms
62,688 KB
testcase_23 AC 435 ms
61,988 KB
testcase_24 AC 529 ms
62,164 KB
testcase_25 AC 128 ms
57,444 KB
testcase_26 AC 128 ms
57,420 KB
testcase_27 AC 356 ms
61,896 KB
testcase_28 AC 353 ms
60,624 KB
testcase_29 AC 498 ms
62,132 KB
testcase_30 AC 499 ms
60,124 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;

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