Array Characteristic
InterviewTime limit2sMemory limit512 MB
Move one element to any position and maximize the weighted sum of A_i times its new index.
- Level
Medium6 of 10
- Topics
- Array, Prefix sum
- Solved
- No attempts yet
Problem
You are given an integer array of length . The characteristic of the array is .
You can pick one element of the array and move it to any position. The destination can be the front of the array, the back of the array, or the position the element already occupies. Removing the element pulls every element behind it one step toward the front, and inserting it pushes every element from the destination onward one step toward the back. You make this move once.
Write a program that computes the maximum value of after one element is moved.
Input
The first line contains . ()
The second line contains separated by spaces. ()
Output
Print the maximum value of after one element is moved, on a single line.