[ICPC2022 Xi’an R] Strange Sum
题目描述
Given a sequence a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an.
You are going to select zero or more elements of a a a so that: if you select a i a_i ai, then in any interval of length i i i (formally, in a [ j , j + i − 1 ] a[j, j + i - 1] a[j,j+i−1] for any 1 ≤ j ≤ n − i + 1 1 \le j \le n - i + 1 1≤j≤n−i+1) you can select at most 2 2 2 elements.
Calculate the maximal sum of the elements you select.
输入格式
The first line contains an integer n n n ( 2 ≤ n ≤ 1 0 5 2 \leq n \leq 10^5 2≤n≤105).
The second line contains n n n integers a 1 , a 2 , … , a n a_1, a_2, \ldots, a_n a1,a2,…,an ( − 1 0 9 ≤ a i ≤ 1 0 9 -10^9 \leq a_i \leq 10^9 −109≤ai≤109).
输出格式
Output a single integer denoting the answer.
样例 #1
样例输入 #1
4
1 4 3 2
样例输出 #1
7
样例 #2
样例输入 #2
3
-10 -10 -10
样例输出 #2
0
提示
Source: The 2022 ICPC Asia Xi’an Regional Contest Problem J.
Author: JohnVictor.
Scratch实现
后续
接下来我会不断用scratch来实现信奥比赛中的算法题、Scratch考级编程题实现、白名单赛事考题实现,感兴趣的请关注,我后续将继续分享相关内容