class Node attr_reader :value, :list def initialize(value = -1, list = []) @list = list.sort @value = value end end class Yukicoder def initialize n, d, k = gets.chomp.split.map(&:to_i) dp = Array.new(k+1){ Array.new(d+1){ Node.new }} dp[0][0] = Node.new(0, []) 1.upto(k) do |i| d.downto(0) do |j| if dp[i-1][j].value >= 0 i.upto(n) do |k| next if dp[i-1][j].list.include?(k) value = dp[i-1][j].value + k next if value > d if dp[i][value].value == -1 dp[i][value] = Node.new(value, dp[i-1][j].list + [k]) elsif (dp[i][value].list <=> dp[i-1][j].list) > 0 dp[i][value] = Node.new(value, dp[i-1][j].list + [k]) end end end end end if dp[k][d].value == -1 puts -1 else puts dp[k][d].list.join(' ') end end end Yukicoder.new