Am I Fired?
Time limit1sMemory limit512 MB
Choose one of four activities each day for N days to maximize satisfaction, subject to at most A rest days, no two lounges in a row, and at least B reading or small-room days.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Greedy, Array, Implementation
- Solved
- No attempts yet
Problem
During SASA's self-study time, each day you can choose one of four options: the reading room, the small study room, the lounge, and resting in your room (recuperation).
Wooseok gets a satisfaction value from each self-study location, and these four values are determined each day by Wooseok's mood.
Wooseok must do self-study for a total of days, and the dormitory has the following rules.
- Recuperation may be requested at most times.
- If he studies in the lounge on two consecutive days, it is judged that he is playing games and he is fired.
- If he studies in the reading room or the small study room fewer than times in total, it is judged that he has lost the will to learn and he is fired.
Wooseok hates studying. Find the maximum possible sum of satisfaction over days such that he is not fired and obeys the dormitory rules.
Input
The first line gives the number of self-study days .
The second line gives the maximum number of recuperation requests and the number of times that he must necessarily study in the reading room and the small study room combined.
From the third line, the -th of lines gives four integers separated by spaces. These values are the satisfaction obtained on the -th self-study day from studying in the reading room, studying in the small study room, studying in the lounge, and recuperation.
Output
Print the maximum possible sum of satisfaction over days such that he obeys the dormitory rules.