PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000041. Chia mảng thành ba phần (Three Parts of the Array)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Chia mảng thành ba phần (Three Parts of the Array)
Three Parts of the Array
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
Given a sequence of positive integers , split it into three consecutive parts in order: prefix, middle part, and suffix. Any part may be empty. The prefix and suffix must have equal sums. Among all valid splits, maximize their common sum. An empty part has sum .
Input
- The first line contains , the sequence length.
- The second line contains exactly integers .
Output
Print the maximum possible common sum of the disjoint prefix and suffix.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
5
1 3 1 1 4
Output
5
Explanation
Take prefix , whose sum is , and suffix , also sum ; the middle is empty. Both parts are disjoint and together use the entire array. They cannot both be extended.