Hide

Problem D
Fishmongers

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 n (1n100000), the number of fish you have to sell, and m (1m100000), the number of fishmongers. On the second line follows n space-separated integers w1,w2,,wn, the weight of each of your fish in kilograms (1wi100000). Finally, there are m lines, the j’th of which consisting of two integers xj (1xj100000) and pj (1pj100000), respectively indicating how many fish the j’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.

Sample Input 1 Sample Output 1
4 3
1 2 7 5
2 4
1 5
3 3
66
Hide

Please log in to submit a solution to this problem

Log in