結果
問題 | No.615 集合に分けよう |
ユーザー |
![]() |
提出日時 | 2018-09-28 14:05:25 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 546 ms / 2,000 ms |
コード長 | 543 bytes |
コンパイル時間 | 1,839 ms |
コンパイル使用メモリ | 75,200 KB |
実行使用メモリ | 49,608 KB |
最終ジャッジ日時 | 2024-10-12 04:49:21 |
合計ジャッジ時間 | 12,138 ms |
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int N = scan.nextInt(); int K = scan.nextInt(); long[]a = new long[N]; for(int i = 0; i < N; i++) { a[i] = scan.nextLong(); } scan.close(); Arrays.sort(a); long[]d = new long[N - 1]; for(int i = 0; i < N - 1; i++) { d[i] = a[i + 1] - a[i]; } Arrays.sort(d); long ans = 0; for(int i = 0; i < N - K; i++) { ans += d[i]; } System.out.println(ans); } }