Skip to content

Instantly share code, notes, and snippets.

@rodoufu
Created August 22, 2018 20:04
Show Gist options
  • Save rodoufu/1dc620544c852ef08eb15c102907e477 to your computer and use it in GitHub Desktop.
Save rodoufu/1dc620544c852ef08eb15c102907e477 to your computer and use it in GitHub Desktop.
New Year Chaos
# Complete the minimumBribes function below.
def minimumBribes(q):
soma = 0
for i in xrange(len(q) - 1, -1, -1):
if q[i] - (i + 1) > 2:
print("Too chaotic")
return
for j in xrange(max(0, q[i] - 2), i):
soma += q[j] > q[i]
print soma
if __name__ == '__main__':
t = int(raw_input())
for t_itr in xrange(t):
n = int(raw_input())
q = map(int, raw_input().rstrip().split())
minimumBribes(q)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment