#P9234. [蓝桥杯 2023 省 A] 买瓜

    ID: 10406 远端评测题 1000ms 256MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>2023O2优化蓝桥杯省赛折半搜索 meet in the middle

[蓝桥杯 2023 省 A] 买瓜

Problem Description

Xiao Lan is buying melons at a melon stall. There are nn melons in total, and the weight of the ii-th melon is AiA_i. Xiao Lan is very skilled with a knife: he can split any melon into two exactly equal halves, but each melon can only be cut once.

Xiao Lan wants the total weight of the melons he buys to be exactly mm.

Please output the minimum number of melons Xiao Lan needs to cut to obtain melons with total weight exactly mm. If no matter what he does he cannot obtain melons with total weight exactly mm, output 1-1.

Input Format

The first line contains two integers n,mn, m, separated by a space, representing the number of melons and the total weight Xiao Lan wants to buy.

The second line contains nn integers AiA_i, separated by spaces, representing the weight of each melon.

Output Format

Output one line containing one integer, the answer.

3 10
1 3 13
2

Hint

Constraints

For 20%20\% of the testdata, n10n \leq 10.

For 60%60\% of the testdata, n20n \leq 20.

For all testdata, 1n301 \leq n \leq 30, 1Ai1091 \leq A_i \leq 10^9, 1m1091 \leq m \leq 10^9.

Translated by ChatGPT 5