Hotel
Time limit4sMemory limit128 MB
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.
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 rooms available. Room costs your friend an upkeep of but only when it is rented, and it holds up to 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 specifies the amount offered to rent one room for a single day, together with the minimum capacity 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 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 , , and (, ): the number of rooms, the number of requests received, and the maximum number of requests your friend will accept.
The next lines describe the rooms; the -th contains two integers and (), the upkeep and the capacity of the room.
The next lines describe the requests; the -th contains two integers and (), the offered rent and the requested minimum capacity.
Output
Print a single integer: the maximum profit obtainable by accepting at most requests. Print if accepting nothing is best. The profit may be large.