結果

問題 No.561 東京と京都
ユーザー k3079kk3079k
提出日時 2019-09-11 15:04:19
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 64 ms / 2,000 ms
コード長 1,237 bytes
コンパイル時間 1,474 ms
コンパイル使用メモリ 63,976 KB
実行使用メモリ 24,008 KB
最終ジャッジ日時 2023-09-15 13:49:03
合計ジャッジ時間 3,925 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 61 ms
23,912 KB
testcase_01 AC 61 ms
23,944 KB
testcase_02 AC 61 ms
24,008 KB
testcase_03 AC 61 ms
23,848 KB
testcase_04 AC 61 ms
23,852 KB
testcase_05 AC 61 ms
22,008 KB
testcase_06 AC 60 ms
21,808 KB
testcase_07 AC 62 ms
23,920 KB
testcase_08 AC 60 ms
21,796 KB
testcase_09 AC 61 ms
23,780 KB
testcase_10 AC 60 ms
21,956 KB
testcase_11 AC 61 ms
21,896 KB
testcase_12 AC 64 ms
21,828 KB
testcase_13 AC 63 ms
23,912 KB
testcase_14 AC 61 ms
19,860 KB
testcase_15 AC 62 ms
21,788 KB
testcase_16 AC 63 ms
23,904 KB
testcase_17 AC 61 ms
23,960 KB
testcase_18 AC 62 ms
23,816 KB
testcase_19 AC 61 ms
23,920 KB
testcase_20 AC 61 ms
21,876 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;

namespace Test01
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int N = input[0];
            int D = input[1];

            int[] t = new int[N + 1];
            int[] k = new int[N + 1];
            for(int i = 1; i <= N; i++)
            {
                input = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
                t[i] = input[0];
                k[i] = input[1];
            }
            //dp[i, j] := i日目にj(0:東京、1:京都)に移動してjの仕事をした時のi日目終了時に得られるお金の最大値
            long[,] dp = new long[N + 1, 2];
            dp[0, 0] = 0;
            dp[0, 1] = 0;
            dp[1, 0] = t[1];
            dp[1, 1] = k[1] - D;
            for(int i = 2; i <= N; i++)
            {
                dp[i, 0] = Math.Max(dp[i - 1, 0] + t[i], dp[i - 1, 1] + t[i] - D);
                dp[i, 1] = Math.Max(dp[i - 1, 1] + k[i], dp[i - 1, 0] + k[i] - D);
            }

            Console.WriteLine(Math.Max(dp[N, 0], dp[N, 1]));
        }
    }
}
0