結果

問題 No.198 キャンディー・ボックス2
ユーザー bluemeganebluemegane
提出日時 2018-10-04 10:11:04
言語 C#(csc)
(csc 3.9.0)
結果
RE  
実行時間 -
コード長 1,201 bytes
コンパイル時間 2,193 ms
コンパイル使用メモリ 102,412 KB
実行使用メモリ 50,132 KB
最終ジャッジ日時 2023-08-02 15:25:31
合計ジャッジ時間 5,020 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 RE -
testcase_01 RE -
testcase_02 TLE -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
testcase_28 -- -
testcase_29 -- -
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System.Linq;
using System.Collections.Generic;
using System;

public class Hello
{
    public static void Main()
    {
        var b = int.Parse(Console.ReadLine().Trim());
        var n = int.Parse(Console.ReadLine().Trim());
        var a = new int[n];
        var amax = 0; var amin = int.MaxValue; var asum = 0;
        for (int i = 0; i < n; i++)
        {
            a[i] = int.Parse(Console.ReadLine().Trim());
            amax = Math.Max(amax, a[i]);
            amin = Math.Min(amin, a[i]);
            asum += a[i];
        }
        var ans = new List<int>();
        for (int i = amin; i <= amax; i++)
        {
            var w = getAns(a, b, asum, n, i);
            if (w != -1) ans.Add(w);
        }
        Console.WriteLine(ans.Min());
    }
    public static int getAns(int[] a, int b, int asum, int n, int t)
    {
        if (asum + b < t * n) return -1;
        if (asum + b == t * n)
        {
            var c = a.Where(x => x - t > 0).Select(x => x - t).Sum();
            return b + c * 2;
        }
        var cm = a.Where(x => x - t < 0).Select(x => x - t).Sum();
        var cp = a.Where(x => x - t > 0).Select(x => x - t).Sum();
        return cp - cm;
    }
}
0