void UseCoffee(ColCoffee c, long MaxNum) { if (MaxNum <= c.Remain) { c.Remain -= MaxNum; Satisfication += c.Satisfication * MaxNum; Days -= MaxNum; } else { Satisfication += c.Satisfication * c.Remain; Days -= c.Remain; c.Remain = 0; } }
void InitTestCase() { Satisfication = 0; string[] InputTxt = Console.ReadLine().Split(); CoffeeVariety = int.Parse(InputTxt[0]); Days = long.Parse(InputTxt[1]); CoffeeList = new ColCoffee[CoffeeVariety]; for (int i = 0; i < CoffeeVariety; i++) { InputTxt = Console.ReadLine().Split(); CoffeeList[i] = new ColCoffee { Remain = long.Parse(InputTxt[0]), Expire = long.Parse(InputTxt[1]), Satisfication = int.Parse(InputTxt[2]), }; } CoffeeList = CoffeeList.OrderByDescending(x => x.Expire).ToArray(); }
void CalcSatisf() { if (CoffeeList.Length == 1) { ColCoffee c = CoffeeList.First(); long q = Days;//3つの中で一番小さい値を調べる if (q > c.Expire) { q = c.Expire; } if (q > c.Remain) { q = c.Remain; } Satisfication = c.Satisfication * q; return; } ColCoffee[] CanDrinkList; ColCoffee UsingCoffee; long CanDrinkCoffee; ColCoffee[] CompareCoffee; while (Days > 0) { CanDrinkList = CoffeeList .Where(x => x.Remain > 0 && x.Expire >= Days) .OrderByDescending(x => x.Satisfication).ToArray(); CanDrinkCoffee = CanDrinkList .Sum(x => x.Remain); if (CanDrinkCoffee == 0)//飲める物がない時 { CompareCoffee = CoffeeList .Where(x => x.Expire < Days).ToArray(); if (CompareCoffee.Count() == 0) { Days = 0; } else { Days -= Days - CompareCoffee.First().Expire; } continue; } else { UsingCoffee = CanDrinkList.First(); CompareCoffee = CoffeeList .Where(x => x.Expire < Days).ToArray(); } if (CompareCoffee.Count() == 0) { UseCoffee(UsingCoffee, Days); } else { UseCoffee(UsingCoffee, Days - CompareCoffee.First().Expire); } } }