Cutting the Tape
InterviewTime limit1sMemory limit128 MB
Split the row of integers into two nonempty parts so the absolute difference of the two part sums is as small as possible.
- Level
Easy3 of 10
- Topics
- Prefix sum, Array
- Solved
- No attempts yet
Problem
Someone found a long tape at home and wrote a row of integers on it. Now they want to cut the tape at a single point, splitting it into two pieces, so that the difference between the sum of the numbers on one piece and the sum on the other piece is as close to as possible. Each piece must contain at least one number. Find the minimum possible absolute value of that difference.
Input
The first line contains the count of numbers on the tape, (). The second line contains the integers () written on the tape, in order.
Output
Print, on a single line, the minimum absolute value of the difference between the sums of the two pieces.
Hint
For example, if the sequence is , cutting after the fourth number splits it into and , and the absolute value of the difference of the two sums is .