Costly Contest
Time limit1sMemory limit512 MB
Split n contestants into k contiguous age divisions and pick a problem subset for each so that the fewest contestants win prizes.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Sorting, Prefix sum
- Solved
- No attempts yet
Problem
The company Mindsight is holding a programming contest for contestants of varying ages. The contest will be separated into age divisions. The duration of the contest will be minutes, the same for all divisions. Mindsight has created a pool of available problems for use in the contest. Since all divisions compete at the same time, the same problems can be used in multiple divisions without any issues.
In each division, the participant who solves the largest number of problems gets a prize. In case of a tie (same number of problems solved), everyone tied for first place gets a prize. If no one in a division solves any problems, then everyone in that division gets a prize.
Mindsight has now come to the horrible realization that with these rules, all participants could win a prize. This could bankrupt the company! So the company has enlisted a team of experts to help resolve the situation.
The expert group analyzed the data in depth. For each of the participants, a slowness factor was determined. For each of the problems, a difficulty rating was assigned. The experts predict that the time it takes for participant to solve problem is minutes. Participants cannot work on multiple problems in parallel, so the time it takes to solve multiple problems is the sum of the times for the individual problems. Participants always solve problems in increasing order of difficulty, starting with the easiest problem.
Now it is up to you, the underpaid intern, to configure the divisions so as to minimize the number of awarded prizes. Your task is to partition the participants into non-empty age divisions, and for each age division choose a non-empty subset of the available problems to use in that division. Each division must correspond to a contiguous age range of participants (for example, a division cannot cover ages 20 to 25 together with ages 30 to 35). The same problem may be used in multiple divisions.
Input
The first line of input contains four integers , , , (, , , ): the number of participants , the number of available problems , the number of age divisions , and the duration of the contest . The second line contains integers (), the slowness factors of the participants. The participants are ordered by age, and no two participants have the same exact age. The third line contains integers (), the difficulty ratings of the problems.
Output
Output a single integer, the minimum number of prize winners.