結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
|
| 提出日時 | 2019-09-11 15:04:19 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 1,237 bytes |
| コンパイル時間 | 3,752 ms |
| コンパイル使用メモリ | 110,476 KB |
| 実行使用メモリ | 27,388 KB |
| 最終ジャッジ日時 | 2024-07-02 16:47:03 |
| 合計ジャッジ時間 | 5,214 ms |
|
ジャッジサーバーID (参考情報) |
judge4 / judge1 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 4 |
| other | AC * 17 |
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
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]));
}
}
}