PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#PS0000289. Tổng lớn nhất tại vị trí chẵn (Maximum Sum on Even Positions)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Tổng lớn nhất tại vị trí chẵn (Maximum Sum on Even Positions)
Maximum Sum on Even Positions
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a positive integer array indexed from zero, reverse at most one contiguous subarray, or leave it unchanged. Maximize the sum of elements at even indices.
Input
First line: . Second line: integers . Each input contains one test case.
Output
Print the maximum attainable sum.
Subtasks
- Subtask 1 (20 points): , . Additionally: .
- Subtask 2 (30 points): , . Additionally: all elements are equal.
- Subtask 3 (50 points): , .
Example 1
Input
8
1 7 3 4 7 6 2 9
Output
26
Explanation
Reverse indices [0,7] to obtain [9, 2, 6, 7, 4, 3, 7, 1]. The even-index sum is 9+6+4+7 = 26.
Example 2
Input
5
1 2 1 2 1
Output
5
Explanation
Reverse indices [0,3] to obtain [2, 1, 2, 1, 1]. The even-index sum is 2+2+1 = 5.
Example 3
Input
10
7 8 4 5 7 6 8 9 7 3
Output
37
Explanation
Reverse indices [1,2] to obtain [7, 4, 8, 5, 7, 6, 8, 9, 7, 3]. The even-index sum is 7+8+7+8+7 = 37.
Example 4
Input
4
3 1 2 1
Output
5
Explanation
Reverse indices [0,0] to obtain [3, 1, 2, 1]. The even-index sum is 3+2 = 5.