using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("5"); WillReturn.Add("3"); WillReturn.Add("1 2 3"); WillReturn.Add("3 2 1"); } else if (InputPattern == "Input2") { WillReturn.Add("9"); WillReturn.Add("2"); WillReturn.Add("8 2"); WillReturn.Add("9 7"); } else if (InputPattern == "Input3") { WillReturn.Add("9"); WillReturn.Add("2"); WillReturn.Add("8 2"); WillReturn.Add("9 5"); } else if (InputPattern == "Input4") { WillReturn.Add("20"); WillReturn.Add("5"); WillReturn.Add("10 7 9 5 7"); WillReturn.Add("5 8 2 8 1"); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } static void Main() { var sw = System.Diagnostics.Stopwatch.StartNew(); List InputList = GetInputList(); int T = int.Parse(InputList[0]); int[] CArr = InputList[2].Split(' ').Select(X => int.Parse(X)).ToArray(); int[] VArr = InputList[3].Split(' ').Select(X => int.Parse(X)).ToArray(); //添字が時間の合計、値が満足度合計の最大値 var SumVArr = new Nullable[T + 1]; SumVArr[0] = 0; int KasanValue = 0; for (int LoopI = 0; LoopI <= CArr.GetUpperBound(0); LoopI += KasanValue) { for (int LoopJ = T; 0 <= LoopJ; LoopJ--) { //時間制限を超えてしまう場合 int wkSumC = LoopJ + CArr[LoopI]; if (wkSumC > T) continue; //満足度の和を求める if (SumVArr[LoopJ] == null) continue; int wkSumV = (SumVArr[LoopJ] ?? 0) + VArr[LoopI]; //満足度合計での最大の満足度を更新可能かを判定 bool CanUpdate = false; if (SumVArr[wkSumC] == null) CanUpdate = true; else if (SumVArr[wkSumC] < wkSumV) CanUpdate = true; if (CanUpdate) { SumVArr[wkSumC] = wkSumV; } } //同じアトラクションに乗った場合は、満足度は半分 VArr[LoopI] /= 2; KasanValue = (VArr[LoopI] == 0 ? 1 : 0); } Console.WriteLine(SumVArr.Max(X => X ?? 0)); } }