Wesley's Anger Contest 2 Problem 5 - Oober Treats

View as PDF

Submit solution


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 F units of fuel, and will have N different candy delivery routes to choose from. Each route takes fi units of fuel and allows you to earn cash each time you complete the route. The first time you complete the ith route, you will earn ai units of cash. For every additional time you complete the route, you will earn bi 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 K 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 Q app changes over time. The ith change will modify the version of the app after the jith change (or the initial version of the app if ji=0) so that the xith delivery route now earns ci units of cash the first time the route is completed, and di units of cash for each additional completion. After each change, print the maximum amount of cash you can earn before running out of fuel.

Constraints

1F,Q,K3000
1N500
1fi3000 for 1iN
1ai,bi109 for 1iN
1ci,di109 for 1iQ
0ji<i for 1iQ
1xiN for 1iQ

Input Specification

The first line of input contains 4 integers, N,Q,F,K.

The next N lines describe the initial candy delivery routes. Each line contains 3 integers, fi,ai,bi.

The next Q lines describe the app changes. Each line contains 4 integers, ji,xi,ci,di.

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 Q lines. On the ith line, output the maximum amount of cash you can earn before running out of fuel after the ith change of the app.

Sample Input

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

Sample Output

Copy
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 2+1+1=4 units of fuel and earns 5+4+3=12 units of cash.

After the second change to the app, we can complete the first route twice, and the second route once. This takes 2+2+1=5 units of fuel and earns 7+3+3=13 units of cash.

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


Comments

There are no comments at the moment.