結果

問題 No.999 てん vs. ほむ
ユーザー bluemeganebluemegane
提出日時 2020-09-11 09:35:22
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 957 ms
コンパイル使用メモリ 65,592 KB
実行使用メモリ 44,724 KB
最終ジャッジ日時 2023-08-26 09:37:11
合計ジャッジ時間 5,327 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 52 ms
20,652 KB
testcase_01 AC 53 ms
20,540 KB
testcase_02 AC 53 ms
22,712 KB
testcase_03 AC 51 ms
20,604 KB
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 AC 60 ms
20,764 KB
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 WA -
testcase_17 AC 111 ms
38,784 KB
testcase_18 AC 113 ms
38,696 KB
testcase_19 AC 113 ms
36,820 KB
testcase_20 AC 112 ms
38,872 KB
testcase_21 AC 121 ms
40,396 KB
testcase_22 AC 120 ms
42,212 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using static System.Math;
using System;

public class Hello
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine().Trim());
        string[] line = Console.ReadLine().Trim().Split(' ');
        var a = Array.ConvertAll(line, int.Parse);
        getAns(n, a);
    }
    static void getAns(int n, int[] a)
    {
        var pL = 0;
        var pr = 2 * n - 1;
        var h = 0L;
        var t = 0L;
        while (pr - pL > 1)
        {
            if (a[pL] - a[pL + 1] >= a[pr] - a[pr - 1])
            {
                h += a[pL];
                t += a[pL + 1];
                pL += 2;
            }
            else
            {
                h += a[pr];
                t += a[pr - 1];
                pr -= 2;
            }
        }
        h += Max(a[pL], a[pr]);
        t += Min(a[pL], a[pr]);
        Console.WriteLine(h - t);
    }
}
0