Under construction

Still being built. Things may change

Hotel

Time limit4sMemory limit128 MB

Summary
Given rooms with capacity and upkeep costs and requests with offered rent and minimum capacity, choose at most o request-room assignments maximizing total rent minus upkeep.
Level

Hard8 of 10

Topics
Greedy, Heap, Sorting
Solved
No attempts yet

Problem

A friend runs a hotel by the sea. As the peak season begins, reservation requests pour in, so your friend asks you to build the reservation system.

The hotel has nn rooms available. Room ii costs your friend an upkeep of cic_i but only when it is rented, and it holds up to pip_i people. Upkeep is monotone in capacity: a room's upkeep is never cheaper than the upkeep of any room that holds fewer people.

The system receives many requests. Request jj specifies the amount vjv_j offered to rent one room for a single day, together with the minimum capacity djd_j of the room it asks for. Each request may be assigned to at most one room, and each room may serve at most one request; an assigned room must have capacity at least the request's minimum. Your friend will accept at most oo requests.

Compute the maximum profit your friend can make (total rent collected minus the upkeep of the rooms actually used) by accepting some of the requests.

Input

The first line contains three integers nn, mm, and oo (1≤n,m≤500 0001 \le n, m \le 500\,000, 1≤o≤min⁡(m,n)1 \le o \le \min(m, n)): the number of rooms, the number of requests received, and the maximum number of requests your friend will accept.

The next nn lines describe the rooms; the ii-th contains two integers cic_i and pip_i (1≤ci,pi≤1091 \le c_i, p_i \le 10^9), the upkeep and the capacity of the room.

The next mm lines describe the requests; the jj-th contains two integers vjv_j and djd_j (1≤vj,dj≤1091 \le v_j, d_j \le 10^9), the offered rent and the requested minimum capacity.

Output

Print a single integer: the maximum profit obtainable by accepting at most oo requests. Print 00 if accepting nothing is best. The profit may be large.

Examples7

  1. Example 1

    Input
    3 2 2
    150 2
    400 3
    100 2
    200 1
    700 3
    
    Expected output
    400
    
  2. Example 2

    Input
    1 1 1
    5 3
    10 2
    
    Expected output
    5
    
  3. Example 3

    Input
    2 1 1
    3 2
    4 3
    100 5
    
    Expected output
    0
    
  4. Example 4

    Input
    2 2 2
    10 2
    20 3
    5 1
    8 1
    
    Expected output
    0
    
  5. Example 5

    Input
    3 3 1
    1 5
    1 5
    1 5
    10 1
    20 1
    15 1
    
    Expected output
    19
    
  6. Example 6

    Input
    2 1 1
    3 5
    7 5
    10 4
    
    Expected output
    7
    
  7. Example 7

    Input
    2 2 2
    2 2
    10 5
    8 1
    20 5
    
    Expected output
    16