#P15614. [ICPC 2021 Jakarta R] Happy Travelling
[ICPC 2021 Jakarta R] Happy Travelling
题目描述
A holiday is coming and Sam plans to visit his parents. There are cities numbered from to . Sam lives in a campus dormitory in city while his parents live in city .
Sam already did some research on the cities. He assigns an integer to each city representing the "happiness value" he will get if he visits city , including city and city .
As for the transportation, he found out that for every city , there is a one-way bus that starts at city and stops at each city from city until city ; in other words, the bus will stop at each of the next cities. It is guaranteed that . When Sam is at city , he will board a bus that starts at city and alight at city where while skipping all the stops between city and city (exclusive). Note that Sam cannot board a bus that does not start at city if he is at city .
Sam likes to be happy but he doesn't like being on a bus for a long time (he gets bored easily). Specifically, if he boards a bus that starts at city and alights at city (where ), then his happiness value will be decreased by the following.
$$\left\lfloor \frac{j - i}{K} \right\rfloor \times D $$Sam is busy preparing souvenirs for his parents and figuring out what to do when he gets there. So he needs your help computing the total maximum happiness value that he can get by carefully planning his journey from city to city .
For example, let , , , , and . The maximum total happiness value that can be obtained from this example is as shown in the following plan.
- Sam starts at city . He obtains a happiness value of at city .
- At city , Sam boards the bus that can stop at any city in and alights at city . His happiness value is decreased by $\left\lfloor \frac{4-1}{2} \right\rfloor \times 1 = 1$ due to this bus trip. He obtains a happiness value of at city .
- At city , Sam boards the bus that can stop at any city in and alights at city . His happiness value is decreased by $\left\lfloor \frac{5-4}{2} \right\rfloor \times 1 = 0$ due to this bus trip. He obtains a happiness value of at city .
- At city , Sam boards the bus that can stop at any city in and alights at city . His happiness value is decreased by $\left\lfloor \frac{6-5}{2} \right\rfloor \times 1 = 0$ due to this bus trip. He obtains a happiness value of at city .
In this plan, Sam boards a bus times with the total happiness value of . No other plan has a better total happiness value than this in this example.
输入格式
Input begins with a line containing three integers (; ; ) representing the number of cities, and the parameter and as defined in the problem description, respectively. The second line contains integers () representing the happiness value Sam will get if he visits city . The third line contains integers (; ) for representing the number of next contiguous cities in which the bus that starts at city will stop at.
输出格式
Output contains an integer in a line representing the maximum total happiness value that can be obtained.
6 2 1
8 -7 -8 9 0 2
5 3 3 2 1
18
8 8 8
10 -5 -5 -5 -5 -5 -5 10
5 2 5 3 2 1 1
15
13 2 2
-5 -4 -4 -1 7 -6 -5 -4 -3 -2 -1 5 -7
3 10 9 8 7 6 5 4 3 2 1 1
-9
提示
Explanation for the sample input/output #2
At city , Sam boards the bus that can stop at any city in and alights at city . At city , Sam boards the bus that can stop at any city in and alights at city . The total happiness value of this plan is $10 + (\left\lfloor \frac{3-1}{8} \right\rfloor \times 8 - 5) + (\left\lfloor \frac{8-3}{8} \right\rfloor \times 8 + 10) = 8 + (0 - 5) + (0 + 10) = 15$.