結果

問題 No.615 集合に分けよう
ユーザー mbanmban
提出日時 2017-12-17 07:19:18
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 114 ms / 2,000 ms
コード長 1,912 bytes
コンパイル時間 4,082 ms
コンパイル使用メモリ 103,832 KB
実行使用メモリ 28,712 KB
最終ジャッジ日時 2023-08-21 14:35:23
合計ジャッジ時間 8,343 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 60 ms
18,756 KB
testcase_01 AC 62 ms
22,740 KB
testcase_02 AC 61 ms
20,664 KB
testcase_03 AC 61 ms
20,872 KB
testcase_04 AC 61 ms
22,808 KB
testcase_05 AC 58 ms
18,828 KB
testcase_06 AC 59 ms
20,772 KB
testcase_07 AC 59 ms
20,880 KB
testcase_08 AC 59 ms
22,784 KB
testcase_09 AC 57 ms
20,664 KB
testcase_10 AC 61 ms
22,820 KB
testcase_11 AC 60 ms
20,872 KB
testcase_12 AC 60 ms
22,748 KB
testcase_13 AC 69 ms
21,036 KB
testcase_14 AC 69 ms
23,000 KB
testcase_15 AC 76 ms
21,892 KB
testcase_16 AC 112 ms
28,644 KB
testcase_17 AC 112 ms
26,736 KB
testcase_18 AC 113 ms
28,712 KB
testcase_19 AC 112 ms
26,600 KB
testcase_20 AC 111 ms
28,700 KB
testcase_21 AC 114 ms
26,764 KB
testcase_22 AC 112 ms
26,648 KB
testcase_23 AC 93 ms
22,560 KB
testcase_24 AC 109 ms
26,148 KB
testcase_25 AC 58 ms
20,780 KB
testcase_26 AC 59 ms
20,800 KB
testcase_27 AC 91 ms
22,552 KB
testcase_28 AC 91 ms
24,456 KB
testcase_29 AC 102 ms
26,896 KB
testcase_30 AC 102 ms
26,864 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Scanner
{
    private readonly char Separator = ' ';
    private int Index = 0;
    private string[] Line = new string[0];
    public string Next()
    {
        if (Index >= Line.Length)
        {
            Line = Console.ReadLine().Split(Separator);
            Index = 0;
        }
        var ret = Line[Index];
        Index++;
        return ret;
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public string[] StringArray()
    {
        Line = Console.ReadLine().Split(Separator);
        Index = Line.Length;
        return Line;
    }

    public int[] IntArray()
    {
        var l = StringArray();
        var res = new int[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = int.Parse(l[i]);
        }
        return res;
    }

    public long[] LongArray()
    {
        var l = StringArray();
        var res = new long[l.Length];
        for (int i = 0; i < l.Length; i++)
        {
            res[i] = long.Parse(l[i]);
        }
        return res;
    }
}

class Program
{
    private int N, K;
    private long[] A;
    private void Scan()
    {
        var sc = new Scanner();
        N = sc.NextInt();
        K = sc.NextInt();
        A = sc.LongArray();
    }


    public void Solve()
    {
        Scan();
        Array.Sort(A);
        var dif = new long[N - 1];
        for (int i = 0; i < N - 1; i++)
        {
            dif[i] = A[i + 1] - A[i];
        }
        Array.Sort(dif);
        long ans = 0;
        for (int i = 0; i < N - K; i++)
        {
            ans += dif[i];
        }
        Console.WriteLine(ans);
    }

    static void Main(string[] args)
    {
        new Program().Solve();
    }
}
0