Skip to content

Instantly share code, notes, and snippets.

@inspirit941
Created April 23, 2020 06:00
Show Gist options
  • Save inspirit941/db8054cbffbb7c44299d8fde0e71c163 to your computer and use it in GitHub Desktop.
Save inspirit941/db8054cbffbb7c44299d8fde0e71c163 to your computer and use it in GitHub Desktop.
import sys
import math
n, k = map(int, sys.stdin.readline().split())
arr = list(map(int, sys.stdin.readline().split()))
answer = math.inf
# 가장 작은 숫자가 맨 앞일 때... 맨 뒤일 때까지.
start_idx = arr.index(min(arr))
for i in range(k):
cnt = 1
front, back = arr[:start_idx-i], arr[start_idx+k-i:]
front_cnt = len(front) // (k-1) + (1 if len(front) % (k-1) else 0)
back_cnt = len(back) // (k-1) + (1 if len(back) % (k-1) else 0)
answer = min(answer, cnt + front_cnt + back_cnt)
print(answer)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment