結果

問題 No.609 Noelちゃんと星々
ユーザー NoNo
提出日時 2018-01-24 02:06:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 147 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 2,703 ms
コンパイル使用メモリ 106,232 KB
実行使用メモリ 37,972 KB
最終ジャッジ日時 2023-08-26 23:59:13
合計ジャッジ時間 6,447 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 122 ms
28,436 KB
testcase_01 AC 96 ms
24,504 KB
testcase_02 AC 88 ms
24,956 KB
testcase_03 AC 95 ms
25,840 KB
testcase_04 AC 83 ms
22,864 KB
testcase_05 AC 132 ms
29,360 KB
testcase_06 AC 121 ms
28,712 KB
testcase_07 AC 101 ms
28,856 KB
testcase_08 AC 76 ms
22,440 KB
testcase_09 AC 88 ms
25,288 KB
testcase_10 AC 109 ms
29,092 KB
testcase_11 AC 108 ms
26,864 KB
testcase_12 AC 118 ms
28,152 KB
testcase_13 AC 78 ms
20,720 KB
testcase_14 AC 74 ms
24,208 KB
testcase_15 AC 125 ms
30,708 KB
testcase_16 AC 142 ms
37,892 KB
testcase_17 AC 119 ms
28,376 KB
testcase_18 AC 87 ms
23,136 KB
testcase_19 AC 125 ms
28,692 KB
testcase_20 AC 144 ms
37,908 KB
testcase_21 AC 142 ms
35,920 KB
testcase_22 AC 147 ms
37,972 KB
testcase_23 AC 145 ms
37,932 KB
testcase_24 AC 145 ms
35,952 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.Linq;

namespace y
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] y = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            Array.Sort(y);

            int c = 0;
            int d = 0;
            if (n == 1)
            {
                c = y[0];
                d = y[0];
            }
            else if (n % 2 == 0)
            {
                c = y[n / 2];
                d = y[n / 2 + 1];
            }
            else
            {
                c = y[n / 2];
                d = y[n / 2 + 1];
            }

            long ans1 = 0;
            long ans2 = 0;

            foreach (var i in y)
            {
                ans1 += Math.Abs(c - i);
                ans2 += Math.Abs(d - i);
            }

            Console.WriteLine((long)Math.Min(ans1, ans2));
        }
    }
}
0