AtCoderのABC
次のABCの問題へ
前のABCの問題へ
ABC258-D Trophy
C#のソース
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
static string InputPattern = "InputX";
static List<string> GetInputList()
{
var WillReturn = new List<string>();
if (InputPattern == "Input1") {
WillReturn.Add("3 4");
WillReturn.Add("3 4");
WillReturn.Add("2 3");
WillReturn.Add("4 2");
//18
}
else if (InputPattern == "Input2") {
WillReturn.Add("10 1000000000");
WillReturn.Add("3 3");
WillReturn.Add("1 6");
WillReturn.Add("4 7");
WillReturn.Add("1 8");
WillReturn.Add("5 7");
WillReturn.Add("9 9");
WillReturn.Add("2 4");
WillReturn.Add("6 4");
WillReturn.Add("5 1");
WillReturn.Add("3 1");
//1000000076
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct ABInfoDef
{
internal long A;
internal long B;
}
static void Main()
{
List<string> InputList = GetInputList();
long[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => long.Parse(pX)).ToArray();
SplitAct(InputList[0]);
long X = wkArr[1];
var ABInfoList = new List<ABInfoDef>();
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
ABInfoDef WillAdd;
WillAdd.A = wkArr[0];
WillAdd.B = wkArr[1];
ABInfoList.Add(WillAdd);
}
var AnswerKouho = new List<long>();
long ABRunSum = 0;
long RunMinB = ABInfoList[0].B;
long StageCnt = 0;
foreach (ABInfoDef EachABInfo in ABInfoList) {
ABRunSum += EachABInfo.A + EachABInfo.B;
RunMinB = Math.Min(RunMinB, EachABInfo.B);
StageCnt++;
long RestStage = X - StageCnt;
if (RestStage < 0) break;
long Kouho = ABRunSum + RestStage * RunMinB;
AnswerKouho.Add(Kouho);
}
Console.WriteLine(AnswerKouho.Min());
}
}
解説
どのステージまでクリアするかを全探索してます。