## Wesley's Anger Contest 2 Problem 5 - Oober Treats

View as PDF

Points: 25
Time limit: 2.5s
Memory limit: 256M

Author:
Problem types

After years of deliberation, you have finally decided to get a job for the fast growing startup called Oober Treats! Oober Treats has decided that rather than having children running around streets on Halloween, the candy will instead be delivered right to their door!

On Halloween night, you will drive a delivery truck that has units of fuel, and will have different candy delivery routes to choose from. Each route takes units of fuel and allows you to earn cash each time you complete the route. The first time you complete the route, you will earn units of cash. For every additional time you complete the route, you will earn units of cash. However, not wanting you to become too bored at the job, your delivery company will only let you complete the same route at most times. If you choose which delivery routes to complete optimally, what is the maximum amount of cash you can earn without running out of fuel?

Of course the cash you earn changes based on the level of demand of the customers. Since Oober Treats did not have enough money to hire good app developers, the prices were hard-coded and each price change will require an update to the app. Sometimes, the developers will realize they need to revert to a previous version of the app before making a change.

There will be a total of app changes over time. The change will modify the version of the app after the change (or the initial version of the app if ) so that the delivery route now earns units of cash the first time the route is completed, and units of cash for each additional completion. After each change, print the maximum amount of cash you can earn before running out of fuel.

for
for
for
for
for

#### Input Specification

The first line of input contains integers, .

The next lines describe the initial candy delivery routes. Each line contains integers, .

The next lines describe the app changes. Each line contains integers, .

#### Output Specification

This problem is graded with an identical checker. This includes whitespace characters. Ensure that every line of output is terminated with a \n character and that there are no trailing spaces.

Output lines. On the line, output the maximum amount of cash you can earn before running out of fuel after the change of the app.

#### Sample Input

2 2 5 2
2 5 2
1 3 1
0 2 4 3
0 1 7 3

#### Sample Output

12
13

#### Sample Explanation

After the first change to the app, we can complete the first route once, and the second route twice. This takes units of fuel and earns units of cash.

After the second change to the app, we can complete the first route twice, and the second route once. This takes units of fuel and earns units of cash.

Note that , so we cannot complete the same route more than twice.