結果

問題 No.615 集合に分けよう
ユーザー tentententen
提出日時 2020-09-05 11:51:32
言語 Java21
(openjdk 21)
結果
AC  
実行時間 532 ms / 2,000 ms
コード長 575 bytes
コンパイル時間 1,870 ms
コンパイル使用メモリ 72,576 KB
実行使用メモリ 61,144 KB
最終ジャッジ日時 2023-08-18 18:04:51
合計ジャッジ時間 11,688 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 115 ms
56,424 KB
testcase_01 AC 120 ms
54,096 KB
testcase_02 AC 115 ms
56,024 KB
testcase_03 AC 116 ms
56,712 KB
testcase_04 AC 114 ms
55,860 KB
testcase_05 AC 115 ms
55,888 KB
testcase_06 AC 117 ms
56,148 KB
testcase_07 AC 127 ms
56,116 KB
testcase_08 AC 123 ms
55,972 KB
testcase_09 AC 125 ms
56,048 KB
testcase_10 AC 119 ms
56,044 KB
testcase_11 AC 127 ms
55,856 KB
testcase_12 AC 121 ms
55,604 KB
testcase_13 AC 167 ms
56,196 KB
testcase_14 AC 168 ms
56,660 KB
testcase_15 AC 277 ms
60,888 KB
testcase_16 AC 487 ms
61,144 KB
testcase_17 AC 496 ms
60,912 KB
testcase_18 AC 479 ms
60,776 KB
testcase_19 AC 484 ms
60,964 KB
testcase_20 AC 484 ms
61,136 KB
testcase_21 AC 532 ms
60,892 KB
testcase_22 AC 494 ms
60,844 KB
testcase_23 AC 383 ms
60,448 KB
testcase_24 AC 472 ms
61,120 KB
testcase_25 AC 119 ms
55,812 KB
testcase_26 AC 117 ms
55,932 KB
testcase_27 AC 378 ms
60,160 KB
testcase_28 AC 350 ms
60,440 KB
testcase_29 AC 433 ms
60,828 KB
testcase_30 AC 452 ms
61,056 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[] dif = new long[n - 1];
    	for (int i = 0; i < n - 1; i++) {
    	    dif[i] = arr[i + 1] - arr[i];
    	}
    	Arrays.sort(dif);
    	long ans = 0;
    	for (int i = 0; i < n - k; i++) {
    	    ans += dif[i];
    	}
    	System.out.println(ans);
	}
}
0