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("7 2"); WillReturn.Add("0 0 1"); WillReturn.Add("1 0 1"); WillReturn.Add("1 1 2"); WillReturn.Add("1 2 1"); WillReturn.Add("2 0 1"); WillReturn.Add("2 1 1"); WillReturn.Add("2 2 1"); WillReturn.Add("-1 -1 2 2 1"); WillReturn.Add("1 0 1 2 1"); //0 //すべての敵を倒したので残り体力の合計は0 } else if (InputPattern == "Input2") { WillReturn.Add("4 1"); WillReturn.Add("1 0 1"); WillReturn.Add("1 2 1"); WillReturn.Add("2 0 2"); WillReturn.Add("2 1 1"); WillReturn.Add("-1 -1 3 3 2"); //0 } else if (InputPattern == "Input3") { WillReturn.Add("4 1"); WillReturn.Add("1 0 2"); WillReturn.Add("1 2 1"); WillReturn.Add("2 0 1"); WillReturn.Add("2 1 1"); WillReturn.Add("-1 0 3 3 1"); //1 } else if (InputPattern == "Input4") { WillReturn.Add("10 10"); WillReturn.Add("-444 -456 6808"); WillReturn.Add("465 31 3659"); WillReturn.Add("-16 103 7545"); WillReturn.Add("199 342 7710"); WillReturn.Add("374 -206 4493"); WillReturn.Add("-15 -286 2504"); WillReturn.Add("-287 155 8841"); WillReturn.Add("-345 -444 3170"); WillReturn.Add("-7 304 9561"); WillReturn.Add("-143 -456 279"); WillReturn.Add("-349 154 13 268 3811"); WillReturn.Add("-40 256 150 80 8822"); WillReturn.Add("486 270 394 337 5486"); WillReturn.Add("310 -342 92 195 6358"); WillReturn.Add("111 -243 209 445 5669"); WillReturn.Add("-224 -120 197 31 904"); WillReturn.Add("436 -206 50 25 7802"); WillReturn.Add("-394 -493 409 229 4934"); WillReturn.Add("-388 367 136 14 3866"); WillReturn.Add("-79 -157 37 426 1670"); //35302 } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct EmemyInfoDef { internal int X; internal int Y; internal int HP; } struct AttackInfoDef { internal int X; internal int Y; internal int Width; internal int Height; internal int Damage; } //60 魔法少女 static void Main() { List InputList = GetInputList(); int[] wkArr = { }; Action SplitAct = pStr => wkArr = pStr.Split(' ').Select(X => int.Parse(X)).ToArray(); SplitAct(InputList[0]); int N = wkArr[0], K = wkArr[1]; var EmemyInfoList = new List(); for (int I = 1; I <= N; I++) { SplitAct(InputList[I]); EmemyInfoList.Add( new EmemyInfoDef() { X = wkArr[0], Y = wkArr[1], HP = wkArr[2] }); } EmemyInfoList.Sort((A, B) => A.X.CompareTo(B.X)); var AttackInfoList = new List(); for (int I = N + 1; I <= InputList.Count - 1; I++) { SplitAct(InputList[I]); AttackInfoDef WillAdd; WillAdd.X = wkArr[0]; WillAdd.Y = wkArr[1]; WillAdd.Width = wkArr[2]; WillAdd.Height = wkArr[3]; WillAdd.Damage = wkArr[4]; AttackInfoList.Add(WillAdd); } AttackInfoList.Sort((A, B) => A.X.CompareTo(B.X)); Solve(EmemyInfoList.ToArray(), AttackInfoList.ToArray()); } static void Solve(EmemyInfoDef[] pEmemyInfoArr, AttackInfoDef[] pAttackInfoArr) { for (int I = 0; I <= pEmemyInfoArr.GetUpperBound(0); I++) { EmemyInfoDef EachEmemyInfo = pEmemyInfoArr[I]; foreach (AttackInfoDef EachAttackInfo in pAttackInfoArr) { if (EachEmemyInfo.X < EachAttackInfo.X) break; if (EachAttackInfo.X <= EachEmemyInfo.X && EachEmemyInfo.X <= EachAttackInfo.X + EachAttackInfo.Width && EachAttackInfo.Y <= EachEmemyInfo.Y && EachEmemyInfo.Y <= EachAttackInfo.Y + EachAttackInfo.Height) { EachEmemyInfo.HP -= EachAttackInfo.Damage; pEmemyInfoArr[I] = EachEmemyInfo; } } } Console.WriteLine(pEmemyInfoArr.Sum(A => Math.Max(0, A.HP))); } }