HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Fyodor Menshikov. Training > problem:


03C. 50615 - Moneybox

Guest
• Discussion of problem (1)

Volume problems

• 02A. 50662 - Prime numbers (2)
• 02B. 50625 - Permutations
• 02C. 50626 - The route
• 02D. 50667 - Intersecting Line Seg...
• 02E. 50607 - Long sum
• 02F. 50647 - Spiral
• 03A. 50633 - The prime factors
• 03B. 50720 - Permutations (2)
• 03C. 50615 - Moneybox
• 03D. 50666 - The card and envelope
• 03E. 50606 - Long product
• 03F. 50616 - Snake
• 04A. 50634 - Perfect numbers
• 04B. 50635 - Decomposition into terms
• 04C. 50608 - Gangsters
• 04D. 50627 - Area of a polygon
• 04E. 50609 - Long division

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
Автор: Фёдор Меньшиков, ВГПУ. Difficulty Gamma

Moneybox

Russian
Given an empty box of weight E and a box filled with coins of weight F. The box may contain N types of coins. For each coin we know the price P and the weight W.
Find the minimum and maximum amount of money that may be in the box.

Input
The first line contains the number E and F, the second line the number N and the following N lines - two numbers, Pi and Wi.
Output
Print two numbers separated by a space - minimum and maximum amounts.
If the box cannot have the exact target weight, provided that it is filled with given coins -print "This is impossible.".

Limitations
1 ≤ EF ≤ 10 000; 1 ≤ N ≤ 500; 1 ≤ Pi ≤ 50 000; 1 ≤ Wi ≤ 10 000.

Input 1 Input 2 Input 3
1000 1100
2
1 1
5 2
1000 1010
2
6 3
2 2
1000 2000
1
10 3
Output 1 Output 2 Output 3
100 250
10 16
This is impossible.

Для отправки решений необходимо выполнить вход.

www.contester.ru