結果
問題 | No.615 集合に分けよう |
ユーザー |
![]() |
提出日時 | 2017-12-15 00:12:27 |
言語 | Java (openjdk 23) |
結果 |
AC
|
実行時間 | 238 ms / 2,000 ms |
コード長 | 1,808 bytes |
コンパイル時間 | 2,645 ms |
コンパイル使用メモリ | 78,420 KB |
実行使用メモリ | 45,816 KB |
最終ジャッジ日時 | 2024-12-14 13:46:22 |
合計ジャッジ時間 | 7,241 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 5 |
other | AC * 26 |
ソースコード
import java.io.*; import java.util.*; class Main { public static void main(String[] args) { MyScanner sc = new MyScanner(); out = new PrintWriter(new BufferedOutputStream(System.out)); int n=sc.nextInt(); int k=sc.nextInt(); long[]a=new long[n]; for(int i=0;i<n;++i)a[i]=sc.nextLong(); Arrays.sort(a); long[]b=new long[n-1]; for(int i=0;i<n-1;++i)b[i]=a[i+1]-a[i]; Arrays.sort(b); long t=0; for(int i=0;i<n-k;++i)t+=b[i]; out.println(t); out.close(); } // http://codeforces.com/blog/entry/7018 //-----------PrintWriter for faster output--------------------------------- public static PrintWriter out; //-----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreElements()) { try { st = new StringTokenizer(br.readLine()); } catch (IOException e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine(){ String str = ""; try { str = br.readLine(); } catch (IOException e) { e.printStackTrace(); } return str; } } }