using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input5"; static List GetInputList() { var WillReturn = new List(); if (InputPattern == "Input1") { WillReturn.Add("3"); WillReturn.Add("1 2 3"); } else if (InputPattern == "Input2") { WillReturn.Add("5"); WillReturn.Add("1 2 3 4 5"); } else if (InputPattern == "Input3") { WillReturn.Add("15"); WillReturn.Add("62 8 90 2 24 62 38 64 76 60 30 76 80 74 72"); } else if (InputPattern == "Input4") { WillReturn.Add("100"); WillReturn.AddRange(Enumerable.Repeat("100", 100)); } else { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } struct JyoutaiDef { internal int CurrP; internal bool[] CanCreateSum; } static void Main() { List InputList = GetInputList(); int[] OmoriArr = InputList.Skip(1).SelectMany(X => X.Split(' '), (X, Y) => int.Parse(Y)).ToArray(); //事前に総合計を求めておく int OmoriSum = OmoriArr.Sum(); //総合計が奇数なら解なし if (OmoriSum % 2 == 1) { Console.WriteLine("impossible"); return; } var stk = new Stack(); JyoutaiDef WillPush; WillPush.CurrP = 0; WillPush.CanCreateSum = new bool[OmoriSum / 2 + 1]; WillPush.CanCreateSum[0] = true; stk.Push(WillPush); bool FoundAnswer = false; while (stk.Count > 0) { JyoutaiDef Popped = stk.Pop(); //クリア判定 if (Popped.CanCreateSum[OmoriSum / 2]) { FoundAnswer = true; break; } if (Popped.CurrP >= OmoriArr.GetUpperBound(0)) continue; WillPush.CurrP = Popped.CurrP + 1; WillPush.CanCreateSum = (bool[])Popped.CanCreateSum.Clone(); for (int I = WillPush.CanCreateSum.GetUpperBound(0); 0 <= I; I--) { if (WillPush.CanCreateSum[I] == false) continue; int wkInd = I + OmoriArr[WillPush.CurrP]; if (wkInd <= WillPush.CanCreateSum.GetUpperBound(0)) { WillPush.CanCreateSum[wkInd] = true; } } stk.Push(WillPush); } Console.WriteLine(FoundAnswer ? "possible" : "impossible"); } }