Conference - Rectification
Time limit1sMemory limit128 MB
Choose a subset of whole reservations to keep so that total income from ticket sales minus room rent is maximized.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy, Brute force, Implementation
- Solved
- No attempts yet
Problem
You may recall the Great Bitonic Conference from the related "Conference" problem. Its organizers need your help once more.
The old registration system maximized the conference income by cancelling some already booked tickets, because fewer attendees means fewer rented rooms and therefore lower expenses. Attendees dislike this: a single reservation groups several tickets booked together, and the old system could cancel part of a reservation while keeping the rest. You must change the system so the income is still maximized, but a reservation may only be cancelled as a whole (either every ticket in it is kept, or every ticket in it is cancelled).
There are presentations. Every attendee of presentation pays the ticket price . The attendees of one presentation are seated in rooms that each hold people, and every rented room costs . If presentation keeps attendees, it needs rooms and earns . Presentations are independent of each other.
Write a program that reads the ticket prices, the room capacity, the room rental cost and the list of reservations, computes the largest total income obtainable when only whole reservations may be cancelled, and prints it.
Input
The first line contains four integers , , and (, , , ), separated by single spaces: 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 separated by single spaces, where is the ticket price of presentation . Each price satisfies and (so a room is already profitable once it is half full).
Each of the next lines describes one reservation by two integers and (, ) separated by a single space: the presentation number and the number of tickets booked in that reservation. A reservation may only be cancelled as a whole.
Output
Print a single integer: the largest total income that can be obtained by cancelling only whole reservations.