[HackerRank][Python3] Sherlock and Cost
2018. 5. 21. 00:21 |
프로그래밍/HackerRank
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))
'프로그래밍 > HackerRank' 카테고리의 다른 글
| [HackerRank][Python3] Big Sorting (0) | 2018.05.29 |
|---|---|
| [HackerRank][Python3] CamelCase (0) | 2018.05.27 |
| [HackerRank][Python3] Journey to the Moon (0) | 2018.05.25 |
| [HackerRank][Python3] Hackerland Radio Transmitters (0) | 2018.05.23 |
| [HackerRank][Python3] Maximum Subarray Sum (0) | 2018.05.18 |
| [HackerRank][Python3] Equal (0) | 2018.05.16 |
| [HackerRank][Python3] The Coin Change Problem (0) | 2018.05.15 |
| [HackerRank][Python3] Super Reduced String (2) | 2018.05.11 |
최근에 달린 댓글 최근에 달린 댓글