Skip to content

Instantly share code, notes, and snippets.

@IKKO-Ohta
Last active July 21, 2017 08:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save IKKO-Ohta/3211822cea95e7cadc290f1476d9471e to your computer and use it in GitHub Desktop.
Save IKKO-Ohta/3211822cea95e7cadc290f1476d9471e to your computer and use it in GitHub Desktop.
N = int(input())
A = [int(x) for x in input().split()]
C = [0 for i in range(N)]
C[1] = A[1] - A[0]
for i in range(N-2):
C[i+2] = min(
C[i]+abs(A[i+2]-A[i]),
C[i+1]+abs(A[i+2]-A[i+1])
)
print(C[-1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment