Skip to content

Instantly share code, notes, and snippets.

@kusano
Created May 31, 2014 16:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kusano/96ae54f26e5feda1fbce to your computer and use it in GitHub Desktop.
Save kusano/96ae54f26e5feda1fbce to your computer and use it in GitHub Desktop.
Google Code Jam 2014 Round 2 B Up and Down
for test in range(input()):
N = input()
A = map(int, raw_input().split())
ans = 0
for i in range(N):
l = 0
r = 0
for j in range(N):
if A[j]>A[i]:
if j<i:
l += 1
else:
r += 1
ans += min(l, r)
print "Case #%s: %s" % (test+1, ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment