競技プログラミングの鉄則
次の問題へ
前の問題へ
A38 Black Company 1
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("5 3");
WillReturn.Add("1 2 22");
WillReturn.Add("2 3 16");
WillReturn.Add("3 5 23");
//100
}
else {
string wkStr;
while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
}
return WillReturn;
}
struct LRHInfoDef
{
internal int L;
internal int R;
internal int H;
}
static List<LRHInfoDef> mLRHInfoList = new List<LRHInfoDef>();
static void Main()
{
List<string> InputList = GetInputList();
int[] wkArr = { };
Action<string> SplitAct = pStr =>
wkArr = pStr.Split(' ').Select(pX => int.Parse(pX)).ToArray();
SplitAct(InputList[0]);
int D = wkArr[0];
int UB = D;
foreach (string EachStr in InputList.Skip(1)) {
SplitAct(EachStr);
LRHInfoDef WillAdd;
WillAdd.L = wkArr[0];
WillAdd.R = wkArr[1];
WillAdd.H = wkArr[2];
mLRHInfoList.Add(WillAdd);
}
int[] MaxHArr = new int[D + 1];
for (int I = 1; I <= UB; I++) {
MaxHArr[I] = 24;
}
foreach (LRHInfoDef EachLRHInfo in mLRHInfoList) {
for (int I = EachLRHInfo.L; I <= EachLRHInfo.R; I++) {
MaxHArr[I] = Math.Min(MaxHArr[I], EachLRHInfo.H);
}
}
int Answer = 0;
for (int I = 1; I <= UB; I++) {
Answer += MaxHArr[I];
}
Console.WriteLine(Answer);
}
}
解説
制約が緩いので、各日ごとに、何時間まで働けるかを配列に持ち
最後に集計してます。