Hostel
InterviewTime limit1sMemory limit1024 MB
Given M bed types with a price and a stock limit each, find the cheapest way to book beds for N participants.
Problem
Arash is organizing the onsite final of PO, the Swedish Potato Peeling Olympiad. participants will come, and Arash needs to book sleeping places for them. Arash has chosen a nearby hostel.
The hostel has types of beds. A bed of type costs kronor, and there are beds of that type available. The hostel has no current bookings, so you can book as many beds as needed.
The Potato Peeling Olympiad team is not strong in math and needs your help. Find the minimum possible cost of booking the beds they need.
Input
The first line contains two integers, the number of participants () and the number of bed types (). The next lines each contain () and () as described above.
There are always enough beds for all participants.
Output
Print one integer on a line: the minimum possible cost for the Swedish Potato Peeling Olympiad to rent beds at the hostel for one night.
Constraints
, , ,
Hint
In the first sample, you buy all 8 of the cheapest beds for a total of 2400, then you buy two of the slightly more expensive beds for a total of 1000. The final price is 3400.