PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN
#TP0000038. Ăn kẹo (Eating Candies)
HỌC THEO LỘ TRÌNH
1 lộ trìnhBài tập thuộc lộ trình
Mục lục đề ⌄
Đang đọc
Ăn kẹo (Eating Candies)
Eating Candies
Source: Codeforces
Version: Phuoc Hung OJ Extended
Problem Statement
There are candies in a row; candy weighs . Alice may eat a prefix from the left, and Bob may eat a suffix from the right. Their chosen candies must be disjoint. They want the total weights they eat to be equal; either player may eat zero candies. Determine the maximum combined number of eaten candies.
Input
- The first line contains , the number of candies.
- The second line contains integers in left-to-right order.
Output
Print the maximum total number of eaten candies while both players eat equal total weights.
Subtasks
- Subtask 1 (20 points): ; for all .
- Subtask 2 (30 points): ; for all .
- Subtask 3 (50 points): ; for all .
Examples
Input
6
2 1 4 2 4 1
Output
6
Explanation
Alice eats the left three candies, weights , total . Bob eats the right three, weights , also total . The chosen sets are disjoint and cover all six candies, so the answer is .