You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Task: There are n piles of stones, where the ith pile has ai stones. You need to collect the maximum number of stones from these piles, but you must fulfill the following condition:
Let's say you pick xi(1<=i<=n)stones from the ith pile, then
x1+x3+x5+.....=x2+x4+x6+...
0<=xi<=ai
For example, if n=3 and a=[2,3,4], you can pick the stones as x=[1,2,1] becuase x1+x3 = 1+1 = 2 and x2 = 2
Find the maximum total number of stones you can pick.
Input Format
The first line of input contains a single integer n denoting the number of piles.
The second line of input contains n space separated integers ai, where the ith integer denoted the number of stones in ith pile.
Constraints
2<=n<=10^5
1<=ai<=10^3
Output Format
Print a single integer denoting the maximum total number of stones you can pick.