Fishmongers
InterviewTime limit1sMemory limit512 MB
Assign each fish to a fishmonger with a weight limit and per-kilogram price so total earnings are maximized.
Problem
You fish fish.
You hate fish.
You love monies.
Therefore sell fish.
To fishmongers.
For maximum profit.
Input
The first line of input contains two integers (), the number of fish you have to sell, and (), the number of fishmongers. The second line contains space-separated integers , the weight of each of your fish in kilograms (). Finally, there are lines, the 'th of which consists of two integers () and (), respectively indicating how many fish the 'th fishmonger wants to buy and how many monies he will pay per kilogram.
Output
A single integer, the maximum number of monies you can obtain by selling your fish to the fishmongers.