Cow Decathlon
Time limit1sMemory limit128 MB
Assign each cow to one event to maximize base scores plus prefix bonuses that cascade when thresholds are met.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
Farmer John's cows (), labeled through as always, are training for a decathlon with events. With a number of events other than ten, -athlon would be the accurate name, but the name stays.
Cow scores points () in event . Each cow competes in exactly one event, and each event has exactly one cow in it.
The team's base score is the sum of the skill levels of the events its cows compete in. The judges hand out bonuses on top of that when a performance impresses them. There are bonuses (), and bonus is given by three integers , , (, , ). If the team earns at least points over the first events, it receives more points.
The points earned over the first events include bonuses already awarded for those same events, so if bonus with has been awarded, its counts too. Bonuses are settled in increasing order of . When several bonuses share the same , keep awarding any bonus whose threshold is met until none is left that qualifies. No bonus is awarded twice.
For example, take cows with these skill levels.
Cow 1 earns the team 7 points if she competes in event 3. Say there is one bonus, worth 6 extra points if the cows score at least 7 points over the first two events. The best assignment sends cow 1 to event 1, cow 2 to event 3, and cow 3 to event 2. Over the first two events cow 1 scores 5 and cow 3 scores 2, which meets the threshold of 7. The total is points.
Assign the cows to events so that the total score is as large as possible.
Input
The first line holds the number of cows and events and the number of bonuses , separated by a space.
Each of the next lines describes one bonus. Line of this block holds , , , separated by spaces.
Each of the next lines holds the skill levels of one cow. Line of this block holds , the points cow scores in each event, separated by spaces.
Output
Print the largest total score the cows can reach, bonuses included.