luogu#P4698. [CEOI 2011] Hotel

[CEOI 2011] Hotel

Problem Description

You run a hotel with nn rooms. Each room has a maintenance cost and a capacity. For room ii, the maintenance cost is cic_i and the capacity is pip_i people.

There are mm orders. Each order has two parameters: vi,div_i, d_i, where viv_i is the rent paid by the order, and did_i is the number of people.

You need to choose some orders and reject the others, so that each chosen order is assigned to exactly one room, and its number of people does not exceed the capacity of that room. Of course, two different orders cannot be assigned to the same room.

You want to know the maximum profit when you choose at most oo orders. The profit of a plan is defined as the sum of rents of the chosen orders minus the sum of maintenance costs of the chosen rooms.

Input Format

The first line contains three integers n,m,on, m, o separated by spaces.

The next nn lines each contain two integers ci,pic_i, p_i separated by spaces.

The next mm lines each contain two integers vi,div_i, d_i separated by spaces.

Output Format

Output one integer, the maximum profit. Note that the answer may be very large.

3 2 2
150 2
400 3
100 2
200 1
700 3
400

Hint

Explanation for Sample 11.

You can assign the first order to the third room, and the second order to the second room.

Constraints

For 100%100\% of the testdata, 1n,m500 0001 \le n, m \le 500\ 000, 1omin(n,m)1 \le o \le \min(n, m), 1ci,pi,vi,di1091 \le c_i, p_i, v_i, d_i \le 10^9. It is guaranteed that for all 1i,jn1 \le i, j \le n, if pi<pjp_i \lt p_j, then cicjc_i \le c_j.

Translated by ChatGPT 5