Addition
InterviewTime limit1sMemory limit1024 MB
Given a sequence, add 1 to three adjacent values per operation to make the odd-position and even-position sums equal, then find the minimum operations or -1.
- Level
Easy3 of 10
- Topics
- Math, Implementation
- Solved
- No attempts yet
Problem
You are given a sequence of integers . You may repeat the following operation as many times as you want.
- Increase three adjacent values by 1 each.
Use as few operations as possible to make the sum of the values at odd positions equal to the sum of the values at even positions. Find the minimum number of operations needed for the odd-position sum and the even-position sum to become equal. If they cannot be made equal, print -1.
Input
The first line contains the length of the sequence. ()
The second line contains the sequence separated by spaces. ()
Output
Print the minimum number of operations needed to make the odd-position sum equal to the even-position sum. If it is impossible, print -1.