using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "InputX"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("2 10000"); WillReturn.Add("20000 32000"); WillReturn.Add("24000 23000"); //45000 } else if (InputPattern == "Input2") { WillReturn.Add("2 10000"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); //100000 } else if (InputPattern == "Input3") { WillReturn.Add("3 10"); WillReturn.Add("42000 50000"); WillReturn.Add("58000 56000"); WillReturn.Add("40000 45000"); //152970 } else if (InputPattern == "Input4") { WillReturn.Add("5 3000"); WillReturn.Add("10000 10000"); WillReturn.Add("20000 23000"); WillReturn.Add("30000 38000"); WillReturn.Add("44000 40000"); WillReturn.Add("54000 56000"); //164000 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct TKInfoDef { internal int T; internal int K; } static void Main() { List InputList = GetInputList(); int[] wkArr = { }; Action SplitAct = pStr => wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray(); SplitAct(InputList[0]); int D = wkArr[1]; var TKInfoList = new List(); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); TKInfoList.Add(new TKInfoDef() { T = wkArr[0], K = wkArr[1] }); } //収入合計[Is東京]なDP表 var PrevDP = new Dictionary(); PrevDP[true] = 0; foreach (TKInfoDef EachTKInfo in TKInfoList) { var CurrDP = new Dictionary(); Action UpdateAct = (pKey, pValue) => { if (CurrDP.ContainsKey(pKey) && CurrDP[pKey] >= pValue) return; CurrDP[pKey] = pValue; }; foreach (var EachPair in PrevDP) { //東京で働く場合 if (EachPair.Key) UpdateAct(true, EachPair.Value + EachTKInfo.T); else UpdateAct(true, EachPair.Value + EachTKInfo.T - D); //京都で働く場合 if (EachPair.Key) UpdateAct(false, EachPair.Value + EachTKInfo.K - D); else UpdateAct(false, EachPair.Value + EachTKInfo.K); } PrevDP = CurrDP; } Console.WriteLine(PrevDP.Values.Max()); } }