結果

問題 No.615 集合に分けよう
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-15 00:12:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 244 ms / 2,000 ms
コード長 1,808 bytes
コンパイル時間 3,963 ms
コンパイル使用メモリ 73,972 KB
実行使用メモリ 42,520 KB
最終ジャッジ日時 2023-08-21 05:00:48
合計ジャッジ時間 7,001 ms
ジャッジサーバーID
(参考情報)
judge15 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 41 ms
33,976 KB
testcase_01 AC 41 ms
33,912 KB
testcase_02 AC 40 ms
33,920 KB
testcase_03 AC 41 ms
33,900 KB
testcase_04 AC 40 ms
33,856 KB
testcase_05 AC 40 ms
33,576 KB
testcase_06 AC 42 ms
33,904 KB
testcase_07 AC 42 ms
33,580 KB
testcase_08 AC 42 ms
33,740 KB
testcase_09 AC 42 ms
33,896 KB
testcase_10 AC 46 ms
33,876 KB
testcase_11 AC 42 ms
34,008 KB
testcase_12 AC 41 ms
33,464 KB
testcase_13 AC 48 ms
33,644 KB
testcase_14 AC 59 ms
34,880 KB
testcase_15 AC 130 ms
37,476 KB
testcase_16 AC 210 ms
42,092 KB
testcase_17 AC 214 ms
42,256 KB
testcase_18 AC 244 ms
42,288 KB
testcase_19 AC 221 ms
42,520 KB
testcase_20 AC 208 ms
41,912 KB
testcase_21 AC 211 ms
42,296 KB
testcase_22 AC 212 ms
42,108 KB
testcase_23 AC 173 ms
41,916 KB
testcase_24 AC 210 ms
42,076 KB
testcase_25 AC 41 ms
33,868 KB
testcase_26 AC 41 ms
33,596 KB
testcase_27 AC 121 ms
41,072 KB
testcase_28 AC 129 ms
40,192 KB
testcase_29 AC 175 ms
41,504 KB
testcase_30 AC 173 ms
40,916 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

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;
        }
    }
}
0