This page is still under construction.

Parts of this page are still being built. What you see may change.

Am I Fired?

Time limit1sMemory limit512 MB

Summary
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 NN days, and the dormitory has the following rules.

  • Recuperation may be requested at most AA 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 BB 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 NN days such that he is not fired and obeys the dormitory rules.

Input

The first line gives the number of self-study days NN.

The second line gives the maximum number of recuperation requests AA and the number of times BB that he must necessarily study in the reading room and the small study room combined.

From the third line, the ii-th of NN lines gives four integers pi,qi,ri,sip_i, q_i, r_i, s_i separated by spaces. These values are the satisfaction obtained on the ii-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 NN days such that he obeys the dormitory rules.

Constraints

  • 1≤N≤1001 \leq N \leq 100
  • 0≤A,B≤N0 \leq A, B \leq N
  • 1≤pi,qi≤ri≤si≤1001 \leq p_i, q_i \leq r_i \leq s_i \leq 100

Examples1

  1. Example 1

    Input
    2
    1 1
    32 91 100 100
    57 8 68 71
    
    Expected output
    162