Min Max Subarrays
시간 제한: 3000ms메모리 제한: 2048MB출처: USACO 2025 February PlatinumBOJ 33738
문제
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
출력
4
예제 2
입력
3 3 1 3
출력
12
예제 3
입력
4 2 4 1 3
출력
22
코드를 제출하려면 로그인하세요.