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("4"); WillReturn.Add("200 100"); WillReturn.Add("300 500"); WillReturn.Add("500 200"); WillReturn.Add("700 100"); //1500 } else if (InputPattern == "Input2") { WillReturn.Add("1"); WillReturn.Add("1000000000 1"); //1 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static long[] GetSplitArr(string pStr) { return (pStr == "" ? new string[0] : pStr.Split(' ')).Select(pX => long.Parse(pX)).ToArray(); } struct ItemInfoDef { internal long AddPower; internal long AttackPlus; } static List mItemInfoList = new List(); static void Main() { List InputList = GetInputList(); long[] wkArr = { }; Action SplitAct = (pStr) => wkArr = GetSplitArr(pStr); foreach (string EachStr in InputList.Skip(1)) { SplitAct(EachStr); ItemInfoDef WillAdd; WillAdd.AddPower = wkArr[0]; WillAdd.AttackPlus = wkArr[1]; mItemInfoList.Add(WillAdd); } mItemInfoList.Reverse(); long UB = mItemInfoList.Count - 1; // 最大スコア[攻撃回数]なDP表 long?[] PrevDP = new long?[UB + 10]; PrevDP[0] = 0; long Answer = long.MinValue; foreach (ItemInfoDef EachItemInfo in mItemInfoList) { long?[] CurrDP = new long?[UB + 10]; for (long I = 0; I <= UB; I++) { if (PrevDP[I].HasValue == false) continue; Action UpdateAct = (pNewInd, pNewVal) => { if (CurrDP[pNewInd].HasValue) { if (CurrDP[pNewInd] >= pNewVal) { return; } } CurrDP[pNewInd] = pNewVal; Answer = Math.Max(Answer, pNewVal); }; // 攻撃する場合 long AddVal = EachItemInfo.AttackPlus; UpdateAct(I + 1, PrevDP[I].Value + AddVal); // 力を増やす場合 UpdateAct(I, PrevDP[I].Value + EachItemInfo.AttackPlus * I); } PrevDP = CurrDP; } Console.WriteLine(Answer); } }