Splitting the Snack
InterviewTime limit1sMemory limit128 MB
Choose which of the N-1 cut points to cut so that both people get exactly N/2 pieces, minimizing the total force of the chosen cuts.
- Level
Medium6 of 10
- Topics
- Dynamic programming, Prefix sum, Array, Greedy
- Solved
- No attempts yet
Problem
There is a stick-shaped snack of length . The snack is made of unit-length pieces glued in a row, so there are cut points, one between each pair of adjacent pieces. The force needed to cut through a point may differ from point to point.
Seonggwan and Dotori want to cut the snack into several pieces and share it so that the total length each person takes is exactly . A point where two pieces going to different people meet must be cut, but there is no need to cut anywhere inside a stretch that a single person takes whole.
Given the force required at each cut point, find the minimum possible total force needed to divide the snack this way.
For example, suppose the snack has length and the forces required to cut each point, from left to right, are . Then cutting as shown below gives the smallest possible total force, .

Input
The first line contains the length of the snack . (, and is even.)
From the second line through the -th line, the force needed to cut each point, from left to right, is given one per line. ()
Output
Print the minimum total force required, on a single line.