Closest Cow Wins
Time limit2sMemory limit1024 MB
Given Nhoj's cow positions, place N of John's cows (not on Nhoj's cows) to maximize the total tastiness of patches John wins.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Sorting, Binary search
- Solved
- No attempts yet
Problem
Farmer John owns a long farm along a highway that can be treated as a one-dimensional number line. The farm has grassy patches (). The -th patch is at position and has tastiness (). Farmer Nhoj, Farmer John's rival, has already placed cows () at positions . All positions are distinct integers in .
Farmer John must choose positions (, not necessarily integers) for his cows. These positions must differ from the positions of Farmer Nhoj's cows, but they may coincide with grassy patches.
Each patch belongs to the owner of the cow closest to it. If a Farmer John cow and a Farmer Nhoj cow are equally close to a patch, Farmer Nhoj claims the patch.
Given the positions of Farmer Nhoj's cows and the positions and tastiness values of the patches, find the maximum total tastiness Farmer John can claim by placing his cows optimally.
Input
The first line contains , , and .
The next lines each contain two integers and .
The next lines each contain one integer .
Output
Print one integer, the maximum total tastiness. The answer can exceed the 32-bit integer range, so use a 64-bit integer type.