import sequtils,strutils,algorithm proc `<`(x,y : seq[int]):bool = # seq[int]をsortするのに必要 for i in 0..min(x.len,y.len): if x[i] < y[i]: return true elif x[i] == y[i]: continue else: return false if x.len < y.len: return true else: return false type kumi = tuple[ku : seq[int],s : int] var N,S : int (N,S) = stdin.readline.split.map(parseInt) var P = newSeq[int](N) p : int ans = newSeq[kumi](0) for n in 0..<N: p = stdin.readline.parseInt P[n] = p if N == 1: if P[0] == S: echo S else: var A = P[0..<(N div 2)] B = P[(N div 2)..<N] Ka : seq[kumi] Ka2 = Ka Kb : seq[kumi] Kb2 = Kb kk : kumi kk = (@[],0) Ka = @[kk] Kb = @[kk] for i,a in A: Ka2 = @[] for k in Ka: Ka2.add((k.ku & @[i + 1] ,k.s + a)) Ka &= Ka2 for i,b in B: Kb2 = @[] for k in Kb: Kb2.add((k.ku & @[i + (N div 2) + 1] ,k.s + b)) Kb &= Kb2 Ka = Ka.sortedByIt(it.s) Kb = Kb.sortedByIt(it.s) Kb.reverse var p = 0 p2 = 0 for i in 0..Ka.high: while p <= Kb.high: if Ka[i].s + Kb[p].s == S: ans.add((Ka[i].ku & Kb[p].ku, Ka[i].s + Kb[p].s)) p += 1 p2 += 1 elif Ka[i].s + Kb[p].s > S: p += 1 elif Ka[i].s + Kb[p].s < S: break p -= p2 p2 = 0 ans = ans.sortedByIt(it.ku) for s in ans: echo s.ku.join(" ")