結果

問題 No.609 Noelちゃんと星々
ユーザー No
提出日時 2018-01-24 02:06:48
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 116 ms / 2,000 ms
コード長 947 bytes
コンパイル時間 2,160 ms
コンパイル使用メモリ 106,496 KB
実行使用メモリ 33,664 KB
最終ジャッジ日時 2024-12-26 03:57:25
合計ジャッジ時間 5,122 ms
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 25
権限があれば一括ダウンロードができます
コンパイルメッセージ
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