#P15676. [ICPC 2024 Jakarta R] Microwavable Subsequence
[ICPC 2024 Jakarta R] Microwavable Subsequence
题目描述
You are given an array of integers: .
A subsequence can be derived from an array by removing zero or more elements without changing the order of the remaining elements. For example, , , , and are subsequences of array , while is not a subsequence of array .
A subsequence is microwavable if the subsequence consists of at most two distinct values and each element differs from its adjacent elements. For example, , , and are microwavable, while and are not microwavable.
Denote a function as the length of the longest microwavable subsequence of array such that each element within the subsequence is either or . Find the sum of for all .
输入格式
The first line consists of two integers ( ).
The second line consists of integers ( ).
输出格式
Output a single integer representing the sum of for all .
5 4
3 2 1 3 2
13
3 3
1 1 1
2
提示
Explanation for the sample input/output #1
The value of is , taken from the subsequence that can be obtained by removing and . The value of is , taken from the subsequence that can be obtained by removing and . The value of is , taken from the subsequence that can be obtained by removing . The value of , , and are all .
Explanation for the sample input/output #2
The value of and are both , while the value of is .