This page is still under construction.

Parts of this page are still being built. What you see may change.

Closest Cow Wins

Time limit2sMemory limit1024 MB

Summary
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 KK grassy patches (1≤K≤2⋅1051 \leq K \leq 2\cdot 10^5). The ii-th patch is at position pip_i and has tastiness tit_i (0≤ti≤1090 \leq t_i \leq 10^9). Farmer Nhoj, Farmer John's rival, has already placed MM cows (1≤M≤2⋅1051 \leq M \leq 2\cdot 10^5) at positions f1…fMf_1 \ldots f_M. All K+MK+M positions are distinct integers in [0,109][0,10^9].

Farmer John must choose NN positions (1≤N≤2⋅1051 \leq N \leq 2\cdot 10^5, 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 KK, MM, and NN.

The next KK lines each contain two integers pip_i and tit_i.

The next MM lines each contain one integer fif_i.

Output

Print one integer, the maximum total tastiness. The answer can exceed the 32-bit integer range, so use a 64-bit integer type.

Examples1

  1. Example 1

    Input
    6 5 2
    0 4
    4 6
    8 10
    10 8
    12 12
    13 14
    2
    3
    5
    7
    11
    
    Expected output
    36