動機
紀錄
Sol
from bisect import bisect_left
def merge(l):
if len(l) < 2:
return [0,l]
else:
a, left = merge(l[:len(l)//2])
b, right = merge(l[len(l)//2:])
ret = a+b
for i in range(len(left)):
ret += bisect_left(right, left[i])
return [ret, sorted(left+right)]
def solution(A):
ret = merge(A)[0]
return ret if ret <= 1000000000 else -1