Min Max Subarrays
시간 제한3초메모리 제한2048 MB
모든 연속 부분 배열에 대해 인접한 두 수를 최소, 최대 연산으로 번갈아 합쳐 마지막에 남을 수 있는 값의 최댓값을 구하고, 그 값들의 합을 출력한다.
문제
You are given a length- integer array (). Output the sum of the answers for the subproblem below over all contiguous subarrays of .
Given a nonempty list of integers, alternate the following operations (starting with the first operation) until the list has size exactly one.
- Replace two consecutive integers in the list with their minimum.
- Replace two consecutive integers in the list with their maximum.
Determine the maximum possible value of the final remaining integer.
For example,
[4, 10, 3] -> [4, 3] -> [4]
[3, 4, 10] -> [3, 10] -> [10]
In the first array, is replaced by and is replaced by .
입력
The first line contains .
The second line contains .
출력
The sum of the answer to the subproblem over all subarrays.