Maximum Absolute Value of the Product of Interval Sums
Time limit1sMemory limit256 MB
Given an integer array and at most K non-overlapping intervals, find the maximum absolute value of the product of the interval sums.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Prefix sum, Math
- Solved
- No attempts yet
Problem
Mathematics has many beautiful symbols. The Math King of Mathland especially likes sums, products, and absolute values. The Math King gave you the following problem.
You are given an integer sequence of length . Then choose at most intervals that do not overlap each other. Each interval must have length at least .
Let the number of intervals be , and let () be the sum of the elements in the -th interval. What is the maximum value of ?
Solve the problem to earn the Math King's respect!
Input
The first line contains .
The next lines contain on the line .
Output
Print the maximum value when at most intervals are chosen, on the first line.
Constraints
- The answer does not exceed .