#4650. Reversible Cards 2
0
Reversible Cards 2
Reversible Cards 2
题目描述
We have cards numbered to .
Card has an integer written on the front and an integer written on the back. Here, .
For each , solve the following problem.
The $N$ cards are arranged so that their front sides are visible. You may choose between $0$ and $N$ cards (inclusive) and flip them.
To make the sum of the visible numbers equal to $k$, at least how many cards must be flipped? Print this number of cards.
If there is no way to flip cards to make the sum of the visible numbers equal to $k$, print $-1$ instead.
输入格式
The input is given from Standard Input in the following format:
输出格式
Print lines. The -th line should contain the answer for .
3 6
0 2
1 0
0 3
1
0
2
1
1
3
2
2 3
1 1
0 1
-1
0
1
-1
5 12
0 1
0 3
1 0
0 5
0 2
1
0
1
1
1
2
1
2
2
2
3
3
4
提示
All values in the input are integers.For , for instance, flipping just card makes the sum of the visible numbers . This choice is optimal.
For , flipping all cards makes the sum of the visible numbers . This choice is optimal.
标签: AtCoder|abc269G
来源
AtCoder|abc269G