結果
| 問題 |
No.561 東京と京都
|
| コンテスト | |
| ユーザー |
suzu
|
| 提出日時 | 2023-05-16 14:43:16 |
| 言語 | C#(csc) (csc 3.9.0) |
| 結果 |
AC
|
| 実行時間 | 30 ms / 2,000 ms |
| コード長 | 994 bytes |
| コンパイル時間 | 953 ms |
| コンパイル使用メモリ | 112,144 KB |
| 実行使用メモリ | 27,440 KB |
| 最終ジャッジ日時 | 2024-12-14 15:09:22 |
| 合計ジャッジ時間 | 2,544 ms |
|
ジャッジサーバーID (参考情報) |
judge5 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| 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.Linq;
using System.Collections.Generic;
namespace yukicoder
{
class Programs
{
static void Main(string[] args)
{
var line1 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
int N = line1[0];
int D = line1[1];
int[,] pay = new int[N,2];
for(int i = 0;i < N;i++)
{
var line2 = Console.ReadLine().Split(' ').Select(c => int.Parse(c)).ToArray();
pay[i,0] = line2[0];//東京
pay[i,1] = line2[1];//京都
}
int[,] dp = new int[N,2];
dp[0,0] = pay[0,0];
dp[0,1] = pay[0,1] - D;
for(int i = 1;i < N;i++)//i日目dp
{
for(int p = 0;p < 2;p++)//今日の東京、京都更新
{
int maxPay = int.MinValue;
for(int q = 0;q < 2;q++)
{
int todayPay = pay[i,p] + dp[i - 1,q];
if(p != q)todayPay -= D;
if(maxPay <= todayPay)maxPay = todayPay;
}
dp[i,p] = maxPay;
}
}
Console.WriteLine(Math.Max(dp[N-1,0],dp[N-1,1]));
}
}
}
suzu