프로그래밍/HackerRank
[HackerRank][Python3] Sherlock and Cost
snoopybox
2018. 5. 21. 00:21
Problem :
https://www.hackerrank.com/challenges/sherlock-and-cost/problem
My Solution :
#!/usr/bin/env python3
def cost(B):
s1, s2 = 0, 0
for i in range(len(B)-1):
ns1 = max(s1, s2 + abs(1 - B[i]))
ns2 = max(s1 + abs(B[i+1] - 1), s2 + abs(B[i+1] - B[i]))
s1, s2 = ns1, ns2
return max(s1, s2)
t = int(input())
for _ in range(t):
n = int(input())
B = list(map(int, input().strip().split()))
print(cost(B))