//#define PRINT using D24._1; using System; using System.Collections.Generic; using System.IO; using System.Linq; namespace D24._2 { class Program { static void Main(string[] args) { if (args.Length < 1) return; if (File.Exists(args[0]) == false) return; List all; Dictionary teams; Dictionary origTeams = new Dictionary(); _1.Program.ParseFile(args, out all, out teams); foreach (var team in teams) origTeams.Add(team.Key, team.Value); int bonus = 2; string bonusTeam = "Immune System"; do { #if PRINT == false Console.Write($"Trying with a boost of : {bonus}\r"); #endif SystemCleanup(all, teams, origTeams, bonus, bonusTeam); while (teams.All(t => t.Value > 0)) { _1.Program.TargetSelectionPhase(all); bool deadlock = _1.Program.AttackPhase(all, teams) == false; if (deadlock) break; } if (teams.Where(t => t.Key != bonusTeam).Sum(t => t.Value) > 0) bonus++; else break; } while (true); int answer = all.Sum(a => a.Number); Console.WriteLine($"\nThe answer is : {answer}"); } private static void SystemCleanup(List all, Dictionary teams, Dictionary origTeams, int bonus, string bonusTeam) { foreach (var team in origTeams) teams[team.Key] = origTeams[team.Key]; foreach (var group in all) { group.Number = group.OrigNumber; group.Healthy = true; if (group.Team != bonusTeam) continue; group.AtkBonus = bonus; } } } }