Conference
InterviewTime limit1sMemory limit128 MB
Given per-presentation ticket prices, room capacity and room rent, and group reservations, choose how many tickets to cancel to maximize revenue minus rent.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Sorting
- Solved
- No attempts yet
Problem
In Bytetown, preparations for the annual Great Bitonic Conference are underway. By tradition, there will be presentations that all take place at exactly the same time. Every presentation is held in identical rooms, and each room holds at most people. There are always enough rooms for everyone. If a presentation is attended by people, it needs rooms.
The organizers want to maximize their profit: ticket revenue minus the cost of renting rooms. Renting one room (capacity ) costs . A ticket to presentation costs . Ticket prices are chosen so that filling a room with people already yields non-negative profit (it may also be profitable with fewer people). The organizers may cancel any number of reserved tickets in order to increase their profit.
Given the ticket prices, the room capacity, the room cost, and every reservation, compute the maximum profit that can be obtained by cancelling some of the reserved tickets.
Here is the smallest integer not smaller than , and is the largest integer not greater than .
Input
The first line contains four integers , , , and (, , , ): the number of presentations, the number of reservations, the capacity of one room, and the cost of renting one room.
The second line contains integers , where and : the ticket price of each presentation (numbered through ).
Each of the next lines contains two integers and (, ): a reservation of tickets for presentation . Within a single reservation any number of tickets may be cancelled, not only the reservation as a whole.
Output
Print one integer: the maximum profit (ticket revenue minus room-rental cost) the organizers can obtain.
Note
In the first example there are presentations with ticket prices , , , a room capacity of , and a room cost of . Presentation has reserved tickets, so with one room the profit is . Presentation has reserved tickets; keeping all would need two rooms, but keeping only (one full room) is more profitable, so tickets are cancelled for a profit of . The total is .