#P5653. Maximizing Weighted Cumulative Sum
Maximizing Weighted Cumulative Sum
Maximizing Weighted Cumulative Sum
YSGH has a number , initially . Over the course of minutes, at each minute (for ) YSGH can add an integer to , where . However, after each minute, the updated value (denoted as ) must satisfy .
Given a sequence of integers , the goal is to choose the increments so as to maximize the objective [ \sum_{i=1}^{n} b_i \cdot w_i, ] where [ b_i = x_{i-1} + y_i, \quad x_0 = 0, \quad \text{and} \quad x_i \le a_i \text{ for } 1\le i\le n. ]
It can be shown that by rewriting the sum as [ \sum_{i=1}^{n} b_i \cdot w_i = \sum_{j=1}^{n} y_j \left(\sum_{i=j}^{n} w_i\right), ] the decision at minute should depend on the sign of [ S(j)=\sum_{i=j}^{n} w_i. ] If , one should choose the maximum possible increment (subject to the constraint at that minute), and if , one should choose the minimum allowed increment.
You are to compute and output the maximum achievable value of the objective.
inputFormat
The input consists of three lines:
- The first line contains two integers and , denoting the number of minutes and the maximum absolute increment allowed each minute, respectively.
- The second line contains integers , where is the upper bound for after the th minute.
- The third line contains integers , representing the weight sequence.
outputFormat
Output a single integer: the maximum possible value of [ \sum_{i=1}^{n} b_i \cdot w_i, ] subject to the conditions described.
sample
3 5
8 10 15
1 2 3
70