Skip to content

Instantly share code, notes, and snippets.

@modos
Created April 26, 2023 11:21
Show Gist options
  • Save modos/71ed1049ed7ab500ee564b63eb4adf04 to your computer and use it in GitHub Desktop.
Save modos/71ed1049ed7ab500ee564b63eb4adf04 to your computer and use it in GitHub Desktop.
تبدیل به حسابی ۲
n, k = map(int, input().split())
a = list(map(int, input().split()))
sum = 0
for i in range(n):
a[i] = a[i]-i*k
sum = sum + a[i]
a.sort()
psum = 0
ans = -1
for i in range(n):
temp = (a[i]*i - psum)
psum = psum + a[i]
temp = temp + (sum - psum - a[i]*(n - 1 - i))
if ans == -1 or temp < ans:
ans = temp
print(ans)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment