using System; using System.Collections.Generic; using System.Text; using System.Linq; class Program { public void Proc() { Reader.IsDebug = false; long[] inpt = Reader.ReadLine().Split(' ').Select(a => long.Parse(a)).ToArray(); int itemCount = (int)inpt[0]; long goukei = inpt[1]; this.nedanList = new long[itemCount]; for (int i = 0; i < itemCount; i++) { nedanList[i] = long.Parse(Reader.ReadLine()); } List ans = this.GetAns(0, goukei); if (ans == null) { Console.WriteLine("-1"); } else { ans.ForEach(a => { StringBuilder str = new StringBuilder(); for (int i = 0; i < itemCount; i++) { long key = 1 << i; if ((a & key) == key) { if (str.Length > 0) { str.Append(" "); } str.Append(i + 1); } } Console.WriteLine(str.ToString()); }); } } private Dictionary>> dic = new Dictionary>>(); private List GetAns(int idx, long remain) { if (!dic.ContainsKey(idx)) { dic.Add(idx, new Dictionary>()); } if (dic[idx].ContainsKey(remain)) { return dic[idx][remain]; } List ans = new List(); if (remain < 0) { return null; } if (remain == 0) { ans.Add(0); return ans; } long key = 1 << idx; if (idx == nedanList.Length - 1) { if(nedanList[idx] == remain) { ans.Add(key); return ans; } else { return null; } } if (this.nedanList[idx] <= remain) { List ret = this.GetAns(idx + 1, remain - this.nedanList[idx]); if (ret != null) { ret.ForEach(a => ans.Add(a + key)); } } List ret2 = this.GetAns(idx + 1, remain); if (ret2 != null) { ans.AddRange(ret2); } if (ans.Count == 0) { ans = null; } dic[idx].Add(remain, ans); return ans; } private long[] nedanList; public class Reader { public static bool IsDebug = true; private static String PlainInput = @" 12 348940 47250 76500 9520 29960 19520 70960 91390 35610 71190 25840 10150 35000 "; private static System.IO.StringReader Sr = null; public static string ReadLine() { if (IsDebug) { if (Sr == null) { Sr = new System.IO.StringReader(PlainInput.Trim()); } return Sr.ReadLine(); } else { return Console.ReadLine(); } } } static void Main() { Program prg = new Program(); prg.Proc(); } }