Last active
July 21, 2017 08:49
-
-
Save IKKO-Ohta/3211822cea95e7cadc290f1476d9471e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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