#P8392. [BalticOI 2022] Uplifting Excursion (Day1)
[BalticOI 2022] Uplifting Excursion (Day1)
Problem Description
There are types of items, with weights . There are items of weight .
You need to take some items such that the sum of their weights is exactly . Under this condition, you need to take as many items as possible.
Ask: with the total weight exactly , what is the maximum number of items you can take.
Input Format
The first line contains two numbers .
The second line contains numbers: .
Output Format
Output one number in a single line, representing the answer. If no solution exists, output impossible.
2 5
2 3 1 1 4
9
3 5
3 1 0 2 0 0 2
impossible
Hint
Subtask ( points): .
Subtask ( points): .
Subtask ( points): .
Subtask ( points): .
Subtask ( points): .
Subtask ( points): no special constraints.
For subtasks to , if you pass the test points with , you can get half of the score.
For all data, , , .
Translated by ChatGPT 5