You are given a integer array positions, where positions[i] is the location of city i on a straight line, and an integer array revenue, where revenue[i] is the revenue from a normal billboard at city i.
You are also given two integers gap and boost.
You may build at most one billboard per city. Any two billboards must be at least gap apart, where the distance between cities i and j is abs(positions[i] - positions[j]).
You may make at most one of the built billboards digital. A digital billboard at city i earns boost * revenue[i] instead of revenue[i], but must be at least 2 * gap from every other billboard.
Return the maximum total revenue.
Example 1:
Input: positions = [1,5,9], revenue = [2,3,4], gap = 4, boost = 2
Output: 10
Explanation:
- Build a digital billboard at
positions[2] = 9, earningboost * revenue[2] = 2 * 4 = 8. - Every other billboard must be at least
2 * gap = 8away from it:positions[2] - positions[1] = 9 - 5 = 4, which is less than 8, so this city is not used.positions[2] - positions[0] = 9 - 1 = 8, which is allowed.
- Build a normal billboard at
positions[0] = 1, earningrevenue[0] = 2. - Total is
8 + 2 = 10.
Example 2:
Input: positions = [1,3,5], revenue = [2,6,3], gap = 2, boost = 2
Output: 12
Explanation:
- Build a digital billboard at
positions[1] = 3, earningboost * revenue[1] = 2 * 6 = 12. - Every other billboard must be at least
2 * gap = 4away from it:positions[1] - positions[0] = 3 - 1 = 2, which is less than 4, so this city is not used.positions[2] - positions[1] = 5 - 3 = 2, which is less than 4, so this city is not used.
- Total is 12, from this single billboard.
Example 3:
Input: positions = [1,3,5], revenue = [2,3,2], gap = 2, boost = 2
Output: 7
Explanation:
- Build normal billboards at all three cities, which is allowed since no digital billboard is required:
positions[1] - positions[0] = 3 - 1 = 2, which is at leastgap = 2.positions[2] - positions[1] = 5 - 3 = 2, which is at leastgap = 2.
- Total is
2 + 3 + 2 = 7.
Constraints:
1 <= positions.length == revenue.length <= 1051 <= positions[i], revenue[i] <= 1051 <= gap, boost <= 105positionsis sorted in strictly increasing order