import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; import java.util.Scanner; public class Yuki015 { public static void main(String[] args) { Yuki015 p = new Yuki015(); } public class Ans extends ArrayList implements Comparable> { @Override public int compareTo(ArrayList o) { for (int i = 0; i < Math.min(this.size(), o.size()); i++) { int comp = Integer.compare(get(i), o.get(i)); if (comp != 0) { return comp; } } return Integer.compare(size(), o.size()); } @Override public String toString() { StringBuilder ans = new StringBuilder(); for (int i = 0; i < size(); i++) { if (ans.length() > 0) { ans.append(" "); } ans.append(get(i)); } return ans.toString(); } } public class HanbunTuple implements Comparable { public long value; public long bit; HanbunTuple(long value, long bit) { this.value = value; this.bit = bit; } @Override public int compareTo(HanbunTuple o) { return Long.compare(this.value, o.value); } } public class Tuple { S a; T b; public Tuple(S a, T b) { this.a = a; this.b = b; } } public Yuki015() { Scanner scanner = new Scanner(System.in); final int N = scanner.nextInt(); final int S = scanner.nextInt(); int[] P = new int[N]; for (int i = 0; i < N; i++) { P[i] = scanner.nextInt(); } int sizeL = N / 2; ArrayList leftList = new ArrayList(2 << sizeL); ArrayList rightList = new ArrayList(2 << sizeL); leftList.add(new HanbunTuple(0, 0)); for (int i = 0; i < sizeL; i++) { int size = leftList.size(); for (int j = 0; j < size; j++) { HanbunTuple tuple = leftList.get(j); leftList.add(new HanbunTuple(tuple.value + P[i], tuple.bit | 1 << i)); } } rightList.add(new HanbunTuple(0, 0)); for (int i = sizeL; i < N; i++) { int size = rightList.size(); for (int j = 0; j < size; j++) { HanbunTuple tuple = rightList.get(j); rightList.add(new HanbunTuple(tuple.value + P[i], tuple.bit | 1 << i)); } } Collections.sort(rightList); ArrayList anses = new ArrayList<>(); for (HanbunTuple tuple : leftList) { final int index = Collections.binarySearch(rightList, tuple, new Comparator() { @Override public int compare(HanbunTuple o1, HanbunTuple o2) { return Long.compare(o1.value, S - o2.value); } }); if (index < 0) { continue; } for (int rightIndex = index; rightIndex < rightList.size(); rightIndex++) { if (rightList.get(rightIndex).value + tuple.value != S) { break; } Ans list = new Ans(); for (long bitIndex = 0; bitIndex < N; bitIndex++) { if ((rightList.get(rightIndex).bit + tuple.bit & 1 << bitIndex) > 0) { //インデックスが1ずれるため list.add((int) bitIndex + 1); } } anses.add(list); } } Collections.sort(anses); for (Ans ans : anses) { System.out.println(ans); } } }