結果

問題 No.2015 Stair Counter
ユーザー 👑 kakel-sankakel-san
提出日時 2022-07-22 21:28:47
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,223 bytes
コンパイル時間 1,900 ms
コンパイル使用メモリ 67,484 KB
実行使用メモリ 41,628 KB
最終ジャッジ日時 2023-09-17 08:53:33
合計ジャッジ時間 5,254 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 63 ms
23,784 KB
testcase_01 AC 100 ms
25,784 KB
testcase_02 AC 104 ms
27,832 KB
testcase_03 AC 105 ms
27,748 KB
testcase_04 AC 98 ms
27,700 KB
testcase_05 AC 96 ms
27,828 KB
testcase_06 AC 110 ms
29,856 KB
testcase_07 AC 108 ms
25,712 KB
testcase_08 AC 110 ms
27,812 KB
testcase_09 AC 101 ms
31,520 KB
testcase_10 AC 102 ms
31,576 KB
testcase_11 AC 105 ms
32,232 KB
testcase_12 AC 96 ms
29,132 KB
testcase_13 AC 97 ms
27,248 KB
testcase_14 AC 100 ms
27,724 KB
testcase_15 AC 108 ms
31,304 KB
testcase_16 AC 139 ms
41,628 KB
testcase_17 AC 103 ms
28,768 KB
testcase_18 AC 129 ms
40,076 KB
testcase_19 AC 142 ms
38,016 KB
testcase_20 AC 120 ms
38,172 KB
testcase_21 AC 98 ms
27,896 KB
testcase_22 AC 102 ms
23,708 KB
testcase_23 AC 107 ms
25,740 KB
testcase_24 AC 100 ms
25,800 KB
testcase_25 AC 100 ms
27,768 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using static System.Console;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static int NN => int.Parse(ReadLine());
    static int[] NList => ReadLine().Split().Select(int.Parse).ToArray();
    static void Main()
    {
        var t = NN;
        var res = new bool[t];
        for (var u = 0; u < t; ++u)
        {
            var c = NList;
            var (n, m) = (c[0], c[1]);
            var a = NList;
            res[u] = Stair(n, m, a);
        }
        WriteLine(string.Join("\n", res.Select(f => f ? "Yes" : "No")));
    }
    static bool Stair(int n, int m, int[] a)
    {
        var dp = new int[n + 1];
        dp[0] = m;
        for (var i = 0; i < n; ++i)
        {
            if (dp[i + 1] < a[i])
            {
                var mv = a[i] - dp[i + 1];
                dp[i] -= mv;
                dp[i + 1] += mv;
            }
            if (i + 2 <= n && dp[i + 2] < a[i + 1])
            {
                var mv = Math.Min(dp[i], a[i + 1] - dp[i + 2]);
                dp[i] -= mv;
                dp[i + 2] += mv;
            }
            if (dp[i] > 0) return false;
        }
        return true;
    }
}
0