結果

問題 No.999 てん vs. ほむ
ユーザー 抹茶アイス
提出日時 2023-08-23 14:37:55
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,174 bytes
コンパイル時間 3,552 ms
コンパイル使用メモリ 111,280 KB
実行使用メモリ 89,828 KB
最終ジャッジ日時 2024-12-21 18:41:28
合計ジャッジ時間 29,205 ms
ジャッジサーバーID
(参考情報)
judge3 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 7 TLE * 7
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Numerics;

namespace yukicoder
{
    public class Program
    {
        public static void Main()
        {
            var n = int.Parse(Console.ReadLine());
            var a = Console.ReadLine().Split().Select(x => long.Parse(x)).ToList();
            long s = 0;
            long v = 0;
            while (a.Count > 0)
            {
                while (a.Count > 0 && a[a.Count - 1] - a[a.Count - 2] >= v)
                {
                    s += a[a.Count - 1] - a[a.Count - 2];
                    a.RemoveAt(a.Count - 1);
                    a.RemoveAt(a.Count - 1);
                }
                if(a.Count > 0)
                {
                    v = a[a.Count - 1] - a[a.Count - 2];
                }
                while (a.Count > 0 && a[0] - a[1] >= v)
                {
                    s += a[0] - a[1];
                    a.RemoveAt(0);
                    a.RemoveAt(0);
                }
                if (a.Count > 0)
                {
                    v = a[0] - a[1];
                }
            }
            Console.WriteLine(s);
        }
    }
}
0