PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000284. Những viên bi và những chiếc hộp (Marbles)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

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 nn marbles and want to buy boxes to store every marble. There are two types of boxes:

  • A type-1 box costs c1c_1 and holds exactly n1n_1 marbles.
  • A type-2 box costs c2c_2 and holds exactly n2n_2 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 m1,m2m_1,m_2 denote their quantities. A feasible allocation satisfies

n1m1+n2m2=n,m1,m2≥0.n_1m_1+n_2m_2=n,\qquad m_1,m_2\ge 0.

Find a feasible allocation minimizing the total cost c1m1+c2m2c_1m_1+c_2m_2. 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 nn, the number of marbles.
  • The second line contains two integers c1,n1c_1,n_1: the price and capacity of a type-1 box.
  • The third line contains two integers c2,n2c_2,n_2: the price and capacity of a type-2 box.

Output

Print one line with the two nonnegative integers m1,m2m_1,m_2, 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): 1≤n≤1001\le n\le 100; 1≤c1,c2≤1001\le c_1,c_2\le 100; 1≤n1≤1001\le n_1\le 100; 1≤n2≤1001\le n_2\le 100; all input values are integers.
  • Subtask 2 (30 points): 1≤n≤1000001\le n\le 100000; 1≤c1,c2≤10001\le c_1,c_2\le 1000; 1≤n1≤10001\le n_1\le 1000; 1≤n2≤10001\le n_2\le 1000; all input values are integers.
  • Subtask 3 (50 points): 1≤n≤20000000001\le n\le 2000000000; 1≤c1,c2≤19999999991\le c_1,c_2\le 1999999999; 1≤n1≤19999999991\le n_1\le 1999999999; 1≤n2≤19999999991\le n_2\le 1999999999; all input values are integers.

Examples

Example 1

Input

43
1 3
2 4

Output

13 1

Explanation

There are 4343 marbles. A type-1 box holds 33 marbles and costs 11, while a type-2 box holds 44 marbles and costs 22. The equation is 3m1+4m2=433m_1+4m_2=43. Its nonnegative solutions are (13,1)(13,1), (9,4)(9,4), (5,7)(5,7) and (1,10)(1,10), with costs 1515, 1717, 1919 and 2121, respectively. The minimum cost is 1515, obtained by 13 1.

Example 2

Input

40
5 9
5 12

Output

failed

Explanation

The box capacities are 99 and 1212, so every sum 9m1+12m29m_1+12m_2 is divisible by 33. Since 4040 is not divisible by 33, there is no allocation using only full boxes.