def main(): import sys input = sys.stdin.read().split() idx = 0 N = int(input[idx]) idx += 1 K = int(input[idx]) idx += 1 A = list(map(int, input[idx:idx+N])) idx += N total = sum(A) if K == 0: print(0) return if K == 1: print(total) return def is_possible_linear(M): current = 0 cnt = 0 for num in A: current += num if current >= M: cnt += 1 current = 0 return cnt >= K def is_possible_circular(M): B = A + A n = len(B) pre_sum = [0] * (n + 1) for i in range(n): pre_sum[i+1] = pre_sum[i] + B[i] max_possible = 0 for i in range(N): j = i current = 0 cnt = 0 while j < i + N: current += B[j] if current >= M: cnt += 1 current = 0 j += 1 max_possible = max(max_possible, cnt) if max_possible >= K: return True return max_possible >= K low = 0 high = total // K best = 0 while low <= high: mid = (low + high) // 2 if mid == 0: best = 0 low = mid + 1 continue if is_possible_linear(mid): best = mid low = mid + 1 else: if is_possible_circular(mid): best = mid low = mid + 1 else: high = mid - 1 print(best) if __name__ == "__main__": main()