Sophie at her hat shop
Sophie works at a hat shop. She is trying to decorate
hats, where each hat
belongs to one of
different designs (denoted by an integer from to ). Each hat also starts with a
different amount of starting beauty .
Hats of the same design share some properties. All hats
belonging to the same design have the same maximum beauty
. Moreover, Sophie
has enough time to devise new decorations. When designing a
decoration, Sophie must pick a design (so that her decorations have
standard measurements). After finishing her design, she then
applies this decoration to each hat of design , resulting in each hat belonging
to that design having its beauty increased by an amount
. However, a hat of
design will never be
able to be more beautiful than . In the case you try to improve
a hat already at peak beauty, the hat simply remains at that
peak. Moreover, Sophie can choose to make multiple decorations
for the same hat design. Sophie wants to maximize the total
beauty of her hats. Thus, after creating new decorations, what is the
maximum possible sum of the beauty of all hats?
Input
The first line of input contains three space separated
integers , , and , denoting the number of hats,
the number of hat designs, and the number of decorations Sophie
can devise, respectively.
Each of the next lines
contains two space separated integers and such that and
,
where represents how
much hats of design
are improved by one decoration and represents the max beauty of
this hat design.
Each of the next lines
contains two space separated integers and
, where represents the design of hat
and represents the amount of
starting beauty of hat .
Output
Output one line containing a single number, representing the
maximum possible sum of the beauty of all hats after Sophie creates
new decorations.
Sample Input 1 |
Sample Output 1 |
4 2 2
1 3
2 5
1 1
1 2
2 4
2 3
|
15
|