You Belong With Me
This problem was inspired by a debate between Parsa and Caterpillow. Don't worry, though, Caterpillow doesn't know about it.
Caterpillow, for the record, you have officially lost our debate. Checkmate.
Now, onto the actual problem.
Ada wants to choose a group of people for an important project. Every person has an intelligence value, and Ada wants the total intelligence of the chosen group to be as large as possible.
There is just one problem: people have very strong opinions about cities.
Each person belongs to exactly one of these two groups:
- people who believe
Sydney > Melbourne; - people who believe
Melbourne > Sydney.
Any two people from the same group can work together peacefully. However, people from different groups may or may not be able to work together. You are given the cross-group pairs that can work together.
Ada wants to choose some people such that every two chosen people can work together. Find the maximum possible total intelligence of such a group.
Input
The first line contains three integers ,
, and
:
is the number of people who believe
Sydney > Melbourne;is the number of people who believe
Melbourne > Sydney;is the number of known compatible pairs between the two groups.
The next lines each contain two integers
and
, meaning person
from the
Sydney > Melbourne group can work together with person from the
Melbourne > Sydney group.
Then, the next line contains integers
(
). The
-th integer is the intelligence value of person
from the
Sydney > Melbourne group.
Finally, the next line contains integers
(
). The
-th integer is the intelligence value of person
from the
Melbourne > Sydney group.
Output
Output one integer: the maximum total intelligence of a group Ada can choose such that every two chosen people can work together.
Sample Input 1
2 2 3
1 2
1 1
2 1
1 5
2 2
Sample Output 1
8
Sample Input 2
2 3 1
1 1
1 1
5 5 5
Sample Output 2
15
Explanation
In the second sample, the best choice is to select only the three people from the
Melbourne > Sydney group. Their total intelligence is .
Comments
light work no reaction