結果

問題 No.198 キャンディー・ボックス2
ユーザー nanophoto12nanophoto12
提出日時 2015-05-05 00:21:12
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,854 bytes
コンパイル時間 2,592 ms
コンパイル使用メモリ 107,276 KB
実行使用メモリ 25,944 KB
最終ジャッジ日時 2023-09-19 06:56:04
合計ジャッジ時間 5,740 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,652 KB
testcase_01 AC 60 ms
21,540 KB
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 AC 61 ms
19,592 KB
testcase_10 AC 61 ms
19,680 KB
testcase_11 AC 61 ms
21,708 KB
testcase_12 AC 62 ms
21,616 KB
testcase_13 WA -
testcase_14 AC 62 ms
21,748 KB
testcase_15 AC 62 ms
21,596 KB
testcase_16 AC 61 ms
23,680 KB
testcase_17 AC 61 ms
21,756 KB
testcase_18 AC 61 ms
21,632 KB
testcase_19 AC 61 ms
21,616 KB
testcase_20 WA -
testcase_21 AC 61 ms
23,788 KB
testcase_22 AC 60 ms
23,804 KB
testcase_23 AC 60 ms
23,676 KB
testcase_24 WA -
testcase_25 AC 60 ms
19,688 KB
testcase_26 AC 61 ms
21,656 KB
testcase_27 WA -
testcase_28 AC 61 ms
21,752 KB
testcase_29 AC 61 ms
21,772 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.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;

namespace No198
{
    class Program
    {
        static void Main(string[] args)
        {
            var hand = long.Parse(Console.ReadLine());
            var n = long.Parse(Console.ReadLine());
            var data = new long[n];
            for (int i = 0; i < n; i++)
            {
                data[i] = long.Parse(Console.ReadLine());
            }
            var sum = hand + data.Sum();
            long minValue = 0;
            long maxValue = sum/n;
            while (maxValue - minValue > 1)
            {
                var minOperation = Calculate(data, minValue);
                var middleValue = (minValue + maxValue) / 2;
                var middleOperation = Calculate(data, middleValue);
                var maxOperation = Calculate(data, maxValue);
                var currentMin = new[] {minOperation, middleOperation, maxOperation}.Min();
                if (currentMin == middleOperation)
                {
                    if (minOperation < maxOperation)
                    {
                        maxValue = middleValue;
                    }
                    else
                    {
                        minValue = middleValue;
                    }
                }
                else
                {
                    break;
                }
            }
            var result = Math.Min(Calculate(data, minValue), Calculate(data, maxValue));
            Console.WriteLine(result);
        }

        private static long Calculate(long[] data, long lastValue)
        {
            var operations = data.Select(element => Math.Abs(element - lastValue)).Sum();
            return operations;
        }
    }
}
0