Life
Time limit2sMemory limit1024 MB
For each prefix of length n, find the minimum total of chosen values when each pick shifts all later A and B values by +U or -D.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
You are given two arrays and of integers each, and two integers and . The -th elements of and are and .
Define as follows.
- For , in order, do the following.
- Choose one of and .
- For every with , if you chose , the values of and each increase by . If you chose , the values of and each decrease by .
is the minimum sum of the chosen numbers over the ways to choose.
For every integer with , find .
Input
The first line contains , , and , separated by spaces. (, )
The second line contains , separated by spaces. ()
The third line contains , separated by spaces. ()
Output
Print lines. On the -th line, print .