#C7311. Minimum Cost to Buy Fruits

    ID: 51169 Type: Default 1000ms 256MiB

Minimum Cost to Buy Fruits

Minimum Cost to Buy Fruits

You are given (T) test cases. In each test case, there are (k) vendors, and you need to purchase exactly (m) apples and (n) bananas. Each vendor offers a bundle that contains a certain number of apples, bananas, and has an associated cost. The bundle from a vendor is represented as a tuple ((a, b, c)) where (a) is the number of apples, (b) is the number of bananas, and (c) is the cost. You can purchase any bundle at most once. Your task is to determine the minimum cost to get exactly (m) apples and (n) bananas. If it is impossible, output -1.

Note: Even if a bundle provides more fruits than needed, the extra fruits are not counted. They are effectively capped at (m) apples and (n) bananas.

inputFormat

The first line of input contains an integer (T) (the number of test cases). For each test case, the first line contains three integers (k), (m), and (n), representing the number of vendors, the required number of apples, and the required number of bananas respectively. Then, (k) lines follow, each containing three integers (a), (b), and (c) describing a vendor's bundle where (a) is the number of apples, (b) is the number of bananas, and (c) is the cost.

outputFormat

For each test case, output a single line containing the minimum cost to purchase exactly (m) apples and (n) bananas. If it is not possible, output -1.## sample

2
3 5 5
3 2 10
4 4 20
2 3 7
1 0 0
1 1 1
17

0

</p>