#GL0000284. Những viên bi và những chiếc hộp (Marbles)
Bài tập thuộc lộ trình
Mục lục đề ⌄
Những viên bi và những chiếc hộp (Marbles)
Marbles
Source: UVa
Version: Phuoc Hung OJ Extended
Problem Statement
You have marbles and want to buy boxes to store every marble. There are two types of boxes:
- A type-1 box costs and holds exactly marbles.
- A type-2 box costs and holds exactly marbles.
Every purchased box must be filled completely. You may purchase any nonnegative number of boxes of either type, including zero boxes of one type. Let denote their quantities. A feasible allocation satisfies
Find a feasible allocation minimizing the total cost . If none exists, report failure. Whenever a feasible allocation exists, the minimum-cost allocation is guaranteed to be unique.
Input
- The first line contains the integer , the number of marbles.
- The second line contains two integers : the price and capacity of a type-1 box.
- The third line contains two integers : the price and capacity of a type-2 box.
Output
Print one line with the two nonnegative integers , the numbers of type-1 and type-2 boxes in the minimum-cost allocation. If no feasible allocation exists, print exactly failed.
Subtasks
- Subtask 1 (20 points): ; ; ; ; all input values are integers.
- Subtask 2 (30 points): ; ; ; ; all input values are integers.
- Subtask 3 (50 points): ; ; ; ; all input values are integers.
Examples
Example 1
Input
43
1 3
2 4
Output
13 1
Explanation
There are marbles. A type-1 box holds marbles and costs , while a type-2 box holds marbles and costs . The equation is . Its nonnegative solutions are , , and , with costs , , and , respectively. The minimum cost is , obtained by 13 1.
Example 2
Input
40
5 9
5 12
Output
failed
Explanation
The box capacities are and , so every sum is divisible by . Since is not divisible by , there is no allocation using only full boxes.