문제
Note: The time limit for this problem is 3s, 1.5x the default.
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.
예제 입력 1
2
2 1
예제 출력 1
4
예제 입력 2
3
3 1 3
예제 출력 2
12
예제 입력 3
4
2 4 1 3
예제 출력 3
22
점수
Inputs 4-5: Inputs 6-7: Inputs 8-9: Inputs 10-13: No additional constraints.
코드를 제출하려면 로그인이 필요합니다.
로그인