結果

問題 No.615 集合に分けよう
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2017-12-15 00:12:27
言語 Java21
(openjdk 21)
結果
AC  
実行時間 238 ms / 2,000 ms
コード長 1,808 bytes
コンパイル時間 2,300 ms
コンパイル使用メモリ 78,112 KB
実行使用メモリ 45,876 KB
最終ジャッジ日時 2024-05-08 10:32:27
合計ジャッジ時間 7,062 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 51 ms
36,904 KB
testcase_01 AC 49 ms
37,252 KB
testcase_02 AC 54 ms
37,356 KB
testcase_03 AC 51 ms
36,808 KB
testcase_04 AC 51 ms
36,892 KB
testcase_05 AC 51 ms
36,896 KB
testcase_06 AC 52 ms
37,252 KB
testcase_07 AC 53 ms
36,796 KB
testcase_08 AC 53 ms
37,424 KB
testcase_09 AC 51 ms
37,160 KB
testcase_10 AC 51 ms
36,936 KB
testcase_11 AC 55 ms
37,416 KB
testcase_12 AC 57 ms
37,524 KB
testcase_13 AC 60 ms
38,088 KB
testcase_14 AC 85 ms
38,648 KB
testcase_15 AC 143 ms
40,800 KB
testcase_16 AC 227 ms
45,876 KB
testcase_17 AC 223 ms
45,252 KB
testcase_18 AC 231 ms
45,528 KB
testcase_19 AC 234 ms
45,384 KB
testcase_20 AC 238 ms
45,256 KB
testcase_21 AC 221 ms
45,392 KB
testcase_22 AC 234 ms
45,616 KB
testcase_23 AC 174 ms
44,708 KB
testcase_24 AC 222 ms
45,176 KB
testcase_25 AC 53 ms
37,224 KB
testcase_26 AC 52 ms
37,108 KB
testcase_27 AC 145 ms
43,412 KB
testcase_28 AC 139 ms
43,220 KB
testcase_29 AC 196 ms
44,612 KB
testcase_30 AC 191 ms
44,180 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