spoj#KNPSACK. Knapsack
Knapsack
Harry is working on a project with Hermione, in which they need some amount of a specific magical powder. As Hermione is studious type, she instructs Harry to arrange X milligrams of powder while she do some other necessary work.
The powder is available in the market in packed form. Packets of different weights are available. There are M types of packets available in the market each having some price, further each type of packet is available in infinite numbers. Your task is to find what is the minimum amount Harry needs to spend so that he can buy at least X milligrams.
Assume that the max value of answer can be 200.00 only.
Input:
In the first line, you are given two integers representing X and M. Next M lines describe the packet details, where each line has two integers Wi(Weight of packet i) and Pi(Price of Packet i). Wi will be a integer where Pi will be decimal number of precision 2.
Output:
You need to print the min. money spent so that Harry can arrange at least X milligrams of powder. Answer must contain exactly two decimal places (i.e. 5 should be printed as 5.00 and 5.6 should be printed as 5.60).
Constraints:
1<=X<=10^7
1<=M<=100
1<=Wi<=10^6
0.01<=Pi<=100.00
Input #1:
3 2
1 1.10
2 0.83
Output #1:
1.66
Input #2:
3 2
2 0.95
1 0.50
Output #2:
1.45