using System; using System.Collections.Generic; using System.Linq; class Program { static string InputPattern = "Input4"; 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 { string wkStr; while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr); } return WillReturn; } 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; } //作成可能な和を保持する配列 bool[] CanCreateNum = new bool[OmoriSum / 2 + 1]; CanCreateNum[0] = true; for (int I = 0; I <= OmoriArr.GetUpperBound(0); I++) { //同じ数を複数回使ってしますので、リバースループにする必要あり for (int J = CanCreateNum.GetUpperBound(0); 0 <= J; J--) { if (CanCreateNum[J] == false) continue; int wkInd = J + OmoriArr[I]; if (wkInd <= CanCreateNum.GetUpperBound(0)) CanCreateNum[wkInd] = true; } } Console.WriteLine(CanCreateNum[OmoriSum / 2] ? "possible" : "impossible"); } }