#QHD0000007. Mua sắm cho đám cưới (Wedding Shopping)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Mua sắm cho đám cưới (Wedding Shopping)
Wedding Shopping
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You have a budget of monetary units to buy clothes from different categories. Category contains models; model has price .
You must purchase exactly one model from each category, spending at most . Among all feasible selections, find the maximum total amount spent.
If the budget cannot cover one model from every category, print no solution.
Input
The first line contains and , the budget and the number of clothing categories.
Each of the next lines starts with , followed by integers , the prices in category .
Output
Print the largest affordable total for exactly one model from each category, or the exact phrase no solution if no valid selection exists.
Subtasks
- Subtask 1 (20 points): ; ; (); (, ).
- Subtask 2 (30 points): ; ; (); (, ).
- Subtask 3 (50 points): ; ; (); (, ).
Examples
Input
100 4
3 8 6 4
2 5 10
4 1 3 3 7
4 50 14 23 8
Output
75
Explanation
Choose items priced from the four groups. Their total is , within the budget. No feasible selection of one item per group has a higher total.