Training
InterviewTime limit1sMemory limit1024 MB
Pick at least one training from each situation so the total time stays within M hours and is as large as possible. Print -1 if no valid plan exists.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
Operations section chief Seungseo must plan the unit's training for the first quarter of 24. To do so, Seungseo selects which trainings to include in the plan.
Trainings are grouped into training situations, and the -th situation consists of trainings. The -th training in the -th situation takes hours.
Seungseo wants to be fully prepared for every situation. So the plan must include at least one training from each situation. The total time of the trainings in the plan cannot exceed hours, and each training can be carried out only once.
Under these conditions, find the maximum total training time that the plan can have.
Input
The first line contains the number of training situations and the maximum training time , separated by a space.
The second line contains integers , the number of trainings in each situation, separated by spaces.
The next lines, starting from line , contain the times of the trainings in the -th situation. Line holds integers , separated by spaces.
Output
Print the maximum total training time that satisfies the conditions.
If it is impossible to pick at least one training from every situation, print -1.
Constraints
- ;
- All input values are integers.