Closest Cow Wins
Farmer John owns a long farm along the highway that can be considered somewhat like a one-dimensional number line. Along the farm, there are k grassy patches; the i-th patch is located at position p[i]
and has an associated tastiness value t[i]
. Farmer John's nemesis, Farmer Nhoj, has already situated his m cows at locations f[1]
..f[m]
. All k + m of these locations are distinct integers in the range [0, 10^9
].
Farmer John needs to pick n locations (not necessarily integers) for his cows to be located. These must be distinct from those already occupied by the cows of Farmer Nhoj, but it is possible for Farmer John to place his cows at the same locations as grassy patches.
Whichever farmer owns a cow closest to a grassy patch can claim ownership of that patch. If there are two cows from rival farmers equally close to the patch, then Farmer Nhoj claims the patch.
Given the locations of Farmer Nhoj's cows and the locations and tastiness values of the grassy patches, determine the maximum total tastiness Farmer John's cows can claim if optimally positioned.
Input
The first line contains k (1 ≤ k ≤ 2 * 10^5
), m (1 ≤ m ≤ 2 * 10^5
) and n (1 ≤ n ≤ 2 * 10^5
).
The next k lines each contain two space-separated integers p[i]
and t[i]
(0 ≤ t[i]
≤ 10^9
).
The next m lines each contain a single integer f[i]
.
Output
Print an integer denoting the maximum total tastiness. Note that the answer to this problem can be too large to fit into a 32-bit integer, so you probably want to use 64-bit integers (e.g., "long long"s in C or C++).
Example
If Farmer John places cows at positions 11.5 and 8 then he can claim a total tastiness of 10 + 12 + 14 = 36.