Problem C
Upplega
Languages
en
sv
Everywhere you go”
It is only truly winter once the snow has settled on all the
branches of the
After a snowy evening, Upplega has settled on all the trees.
Upplega is the Swedish term for snow that has accumulated on
top of a tree’s branches. On each unit length of each branch,
there is
You are a true winter enthusiast who loves Christmas songs, the cozy cold weather, and above all, all the Upplega. According to the weather forecast, there will soon be a big storm that will shake all the trees quite vigorously. When a tree is shaken, the snow on its branches will start falling straight down until the snow either safely lands on a branch belonging to a tree that is not shaking, or lands on the ground.
Despite the storm approaching, you have time to protect
![\includegraphics[width=0.8\textwidth ]{sample1.png}](/problems/upplega/file/statement/en/img-0001.png)
Input
The first row of input contains two integer
The second row contains
The third line contains
Finally,
-
The first row contains
integers ( ), where is the height of the :th branch belonging to tree . -
The second row contains
integers ( , ). Each describes the length and direction of the :th branch of tree . If is positive, it means that branch is directed to the right and is length units long. If is negative, the branch is directed to the left and is length units long.
No branch will be outside the beginning of the street
located at
Output
Print the maximum number of snow units that you can prevent
from falling to the ground by rooting exactly
Scoring
Your solution will be tested on a set of test groups, each worth a number of points. Each test group contains a set of test cases. To get the points for a test group you need to solve all test cases in the test group.
Group |
Point value |
Constraints |
|
|
All branches are directed to the right. Formally,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
No additional constraints. |
Group 4 and 6 additionally guarantee that all trees and
branches have positions in the interval between position
Explanation of sample 1:
By choosing to save the first and second tree, we prevent
Sample Input 1 | Sample Output 1 |
---|---|
3 2 5 11 21 4 4 3 3 3 5 5 -3 3 -2 2 3 6 7 8 8 -2 4 -4 6 7 8 -7 5 -4 |
37 |
Sample Input 2 | Sample Output 2 |
---|---|
1 1 1000 4 10 5 8 6 2 3 -4 -5 |
14 |
Sample Input 3 | Sample Output 3 |
---|---|
2 2 1 2 1 2 1 -1 1 2 1 2 |
4 |