1, 3, 5 Segments
InterviewTime limit1.35sMemory limit1024 MB
Split a sequence of N integers into 6 contiguous segments (empty segments allowed) to maximize the sum of segments 1, 3, and 5.
- Level
Medium4 of 10
- Topics
- Dynamic programming, Prefix sum
- Solved
- No attempts yet
Odd Segments
Jeongmo has been given the following assignment.
"Given a sequence of integers , split the sequence into contiguous segments. Number the segments st, nd, , th from left to right. Find the maximum possible sum of the elements contained in segments , , and ."
Every element must belong to exactly one segment, and a segment may contain no elements. If a segment contains no elements, the sum of its elements is .
Tell Jeongmo the answer so the lazy student can skip the work!
Input
The first line contains the length of the sequence . ()
The second line contains the sequence . ()
Output
Print the answer to the assignment on the first line.