PERMIT
An employee has determined which of the next days they will drive to the office.
We thus consider a function drive : {1, . . . , T }
{0, 1}
such that drive(i) = 1
if the employee drives to work, and drive(i) = 0
otherwise, for .
The employee can only park in the sheltered area near the office, which requires a permit.
There are different types of permits available: , , , where , , and permit has a duration of days and costs euros, for
We assume that the longer the duration of a permit type, the lower the cost per day (i.e., if , then ). For example, there might be a daily permit costing euro, a weekly permit costing euros, a monthly permit costing euros, a six-month permit costing euros, and a yearly permit costing euros.
Formulate and implement the most efficient algorithm possible to calculate a collection of permits with the minimum cost that covers all the days the employee drives to the office.
Input
Your program should read its input from the text file "permit.in".
The first line contains and , the second line contains the values of the function drive
, and the next lines contain the pair (duration, cost) for each permit type.
Output
The output of the program should be written to the file "permit.out". It should report the total cost of the permits purchased, on the first line.
Constraints
Time Limit: 1 sec.
Maximum Available Memory: 128 MB.
Example of Input - Output
STDIN (permit.in)
14 3
1 0 1 1 1 1 1 0 1 0 0 0 0 1
1 1
7 5
14 10
STDOUT (permit.out)
7
Comments