結果

問題 No.198 キャンディー・ボックス2
コンテスト
ユーザー bluemegane
提出日時 2018-10-04 10:11:04
言語 C#(csc)
(csc 3.9.0)
コンパイル:
csc -langversion:latest -unsafe -warn:0 -o+ /r:System.Numerics.dll _filename_ -out:a.exe
実行:
/usr/bin/mono a.exe
結果
RE  
実行時間 -
コード長 1,201 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 850 ms
コンパイル使用メモリ 107,904 KB
実行使用メモリ 45,508 KB
最終ジャッジ日時 2026-04-29 01:18:55
合計ジャッジ時間 5,271 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge1_1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample -- * 4
other RE * 2 TLE * 1 -- * 24
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #
raw source code

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