Problem Author: | Hasan Saleh (MathModel) |
Prepared by: | Hasan Saleh (MathModel) |
Edited by: | Hasan Saleh (MathModel) |
Solution
Observe all distances except a_1 will be travelled twice , i.e. the process will be as following :
So the simulation ends up being :
Complexity .
def solve():
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):ans+=2*a[i]
print(ans)
for _ in range(int(input())):
solve()