Description

Farmer John realizes that the income he receives from milk production is insufficient to fund the growth of his farm, so to earn some extra money, he launches a cow-rental service, which he calls “USACOW” (pronounced “Use-a-cow”). Farmer John has NN cows (1N100,000)(1≤N≤100,000), each capable of producing some amount of milk every day. The MM stores near FJ’s farm (1M100,000)(1≤M≤100,000) each offer to buy a certain amount of milk at a certain price. Moreover, Farmer John’s R(1R100,000)R (1≤R≤100,000) neighboring farmers are each interested in renting a cow at a certain price. Farmer John has to choose whether each cow should be milked or rented to a nearby farmer. Help him find the maximum amount of money he can make per day.

Input

The first line in the input contains NN, MM, and RR. The next N lines each contain an integer ci(1ci1,000,000)ci (1≤c_i≤1,000,000), indicating that Farmer John’s ith cow can produce cic_i gallons of milk every day. The next M lines each contain two integers qiq_i and pi(1qi,pi1,000,000)p_i (1≤q_i,p_i≤1,000,000), indicating that the ith store is willing to buy up to qi gallons of milk for pi cents per gallon. Keep in mind that Farmer John can sell any amount of milk between zero and qiq_i gallons to a given store. The next RR lines each contain an integer ri(1ri1,000,000)r_i (1≤r_i≤1,000,000), indicating that one of Farmer John’s neighbors wants to rent a cow for rir_i cents per day.

Output

The output should consist of one line containing the maximum profit Farmer John can make per day by milking or renting out each of his cows.

Sample Input

5 3 4
6
2
4
7
1
10 25
2 10
15 15
250
80
100
40

Sample Output

725


题意:
有n个牛,每个牛一天产cic_i加仑的奶
有m个店,可以最多卖qiq_i的奶,每单位奶卖pip_i
有r个农场,可以以一头牛rir_i元出租一天
问:一天最多赚多少钱


做法:
把每个牛产的奶从大到小排序
每个店卖的单价从大到小排序
把每个牛产的奶优先往贵的店卖,卖光后每个牛都有一个价值(产的奶卖的价格)
按牛产奶量从小到大(等价于价值从小到大),出租价格从大到小,这样比较,如果这一头牛卖奶的价值小于出租的价值,就出租(这个牛的价值赋值为租出去的价格)。
把每个牛的价值求和即为答案。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#include<iostream>
#include<stdio.h>
#include<string>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
const int MAXN = 100000 + 5;
ll n, m, r;
ll niu[MAXN];
struct dd
{
ll up;
ll p;
bool operator<(const dd xd)const {
if (p == xd.p)
return up > xd.up;
return p > xd.p;
}
}d[MAXN];
ll zu[MAXN];
ll jia[MAXN];
bool cmp(ll a, ll b)
{
return a > b;
}
int main()
{
scanf("%lld%lld%lld", &n, &m, &r);
for (int i = 0; i < n; i++)
{
scanf("%lld", &niu[i]);
}
for (int i = 0; i < m; i++)
{
scanf("%lld%lld", &d[i].up, &d[i].p);
}
for (int i = 0; i < r; i++)
{
scanf("%lld", &zu[i]);
}
sort(d, d + m);
sort(niu, niu + n,cmp);
sort(zu, zu + r, cmp);
int k = 0;
for (int i = 0; i < n; i++)
{
if (k >= m)
{
break;
}
while (niu[i]>0)
{
if (k >= m)
{
break;
}
if (niu[i] >= d[k].up)
{
niu[i] -= d[k].up;
jia[i] += d[k].up*d[k].p;
d[k].up = 0;
k++;
}
else
{
jia[i] += niu[i] * d[k].p;
d[k].up -= niu[i];
niu[i] = 0;
}
}
}
k = 0;
for (int i = n - 1; i >= 0; i--)
{
if (k >= r)
break;
if (jia[i] < zu[k])
{
jia[i] = zu[k];
k++;
}
}
ll ans = 0;
for (int i = 0; i < n; i++)
{
ans += jia[i];
}
printf("%lld\n", ans);
}