Created
April 26, 2023 11:20
-
-
Save modos/07ef59679bf48169243fce1a0745da68 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, k = map(int, input().split()) | |
a = list(map(int, input().split())) | |
val = 1000 * 1000 * 1000 | |
for x in range(-100000, 100000): | |
t = 0 | |
for i in range(n): | |
t += abs((x + i * k) - a[i]) | |
val = min(val, t) | |
print(val) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
این کد با توجه به تست بنده در سایت کوئرا در تاریخ 23 شهریور 1402 به صورت 68 درصد تکمیل جواب میده و در تست های آخر تایم لیمیت میخوره
از کد ویرایش شده زیر که رنج اعداد کاهش پیدا کردن میتونید برای حل مسئله استفاده کنید: