Zen gardens are intended to serve as an intimate imitation of nature as to aid in meditation about the true meaning of life. Therefore, Blake has decided to spend her summer building one in her backyard.
Each flower has a harmony value, and so she's planted
The total harmony value of a Zen garden is given by the sum of all flower harmony values minus the sum of all disturbance values. As she wants her garden to have the maximum harmony, she can remove flowers as to eliminate the disturbance they cause.
What is the maximum overall harmony value that Blake can hope to get out of her garden?
Input Specification
The first line of input will consist of the single integer
The second line will consist of
The next line will consist of the single integer
The next
It is guaranteed that all flowers will at most be part of one pair.
Output Specification
Output the maximum possible overall meditation value of the garden.
Sample Input
4
5 10 15 20
2
1 30
3 4
Sample Output
41
Explanation for Sample Output
After removing the first flower, the sum of the first two flowers is
Comments