Kevin Sun wants to move his precious collection of n cowbells from Naperthrill to Exeter, where there is actually grass instead of corn. Before moving, he must pack his cowbells into k boxes of a fixed size. In order to keep his collection safe during transportation, he won't place more than two cowbells into a single box. Since Kevin wishes to minimize expenses, he is curious about the smallest size box he can use to pack his entire collection. 

Kevin is a meticulous cowbell collector and knows that the size of his i-th (1 ≤ i ≤ n) cowbell is an integer s_{i}. In fact, he keeps his cowbells sorted by size, so s_{i} - 1 ≤ s_{i} for any i > 1. Also an expert packer, Kevin can fit one or two cowbells into a box of size s if and only if the sum of their sizes does not exceed s. Given this information, help Kevin determine the smallest s for which it is possible to put all of his cowbells into k boxes of size s.


-----Input-----

The first line of the input contains two space-separated integers n and k (1 ≤ n ≤ 2·k ≤ 100 000), denoting the number of cowbells and the number of boxes, respectively.

The next line contains n space-separated integers s_1, s_2, ..., s_{n} (1 ≤ s_1 ≤ s_2 ≤ ... ≤ s_{n} ≤ 1 000 000), the sizes of Kevin's cowbells. It is guaranteed that the sizes s_{i} are given in non-decreasing order.


-----Output-----

Print a single integer, the smallest s for which it is possible for Kevin to put all of his cowbells into k boxes of size s.


-----Examples-----
Input
2 1
2 5

Output
7

Input
4 3
2 3 5 9

Output
9

Input
3 2
3 5 7

Output
8



-----Note-----

In the first sample, Kevin must pack his two cowbells into the same box. 

In the second sample, Kevin can pack together the following sets of cowbells: {2, 3}, {5} and {9}.

In the third sample, the optimal solution is {3, 5} and {7}.

Difficulty: MEDIUM
Tags: Sorting

Greedy algorithms
Skill types: Sorting

Greedy algorithms

Starter code:

Solutions:
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
ans = s[-1]
if k >= n:
	print(ans)
else:
	single = 2 * k - n
	for i in range(n - single):
		ans = max(ans, s[i] + s[-single - 1 - i])
	print(ans)


(n, k) = map(int, input().split())
l = sorted(map(int, input().split()))
ma = l[-1]
if k >= n:
	print(ma)
else:
	kk = 2 * k - n
	for i in range((n - kk) // 2):
		j = n - kk - 1 - i
		t = l[i] + l[j]
		if t > ma:
			ma = t
	print(ma)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
s = [-1] + s
if n <= k:
	print(s[n])
else:
	sol = s[n]
	for i in range(n - k):
		x = s[n - k - i] + s[n - k + 1 + i]
		if x > sol:
			sol = x
	print(sol)


(n, k) = list(map(int, input().strip().split()))
a = list(map(int, input().strip().split()))
l = max(a) - 1
r = 100000000001

def check(s):
	count = 0
	l = 0
	r = n - 1
	while l <= r:
		if l != r and a[l] + a[r] <= s:
			count += 1
			l += 1
			r -= 1
		else:
			r -= 1
			count += 1
	if count <= k:
		return True
	else:
		return False
while r - l > 1:
	m = (r + l + 1) // 2
	if check(m):
		r = m
	else:
		l = m
print(r)


(n, m) = map(int, input().split())
a = input().split()
s = int(a[-1])
for i in range(n - m):
	s = max(s, int(a[i]) + int(a[2 * n - 2 * m - i - 1]))
print(s)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
p1 = []
p2 = []
if n <= k:
	print(max(s))
else:
	for i in range(n - k):
		p1.append(s[i] + s[2 * (n - k) - i - 1])
		p2.append(s[2 * i] + s[2 * i + 1])
	for i in range(n - k + 1, n):
		p1.append(s[i])
		p2.append(s[i])
	print(min(max(p1), max(p2)))


import sys

def main():
	(n, k) = map(int, sys.stdin.readline().split())
	s = list(map(int, sys.stdin.readline().split()))
	s = [-1] + s
	if n <= k:
		print(s[n])
	else:
		sol = s[n]
		for i in range(n - k):
			x = s[n - k - i] + s[n - k + 1 + i]
			if x > sol:
				sol = x
		print(sol)
main()


import heapq
from bisect import bisect_left, bisect_right
from itertools import accumulate
R = lambda : map(int, input().split())
(n, k) = R()
objs = sorted(list(R()), reverse=True)
q = [0] * k
res = 0
for o in objs:
	t = heapq.heappop(q)
	if t:
		res = max(res, t + o)
	else:
		heapq.heappush(q, o)
print(max(q + [res]))


(a, b) = map(int, input().split(' '))
x = list(map(int, input().split(' ')))

def f(num):
	lo = 0
	hi = a - 1
	ct = 0
	while lo <= hi:
		if lo == hi:
			ct += 1
			break
		if x[lo] + x[hi] <= num:
			lo += 1
			hi -= 1
		else:
			hi -= 1
		ct += 1
	return ct
lo = max(x)
hi = 100000000
while lo < hi:
	mid = (lo + hi) // 2
	if f(mid) > b:
		lo = mid + 1
	else:
		hi = mid
print(lo)


(n, k) = map(int, input().split())
size = list(map(int, input().split()))
l = size[-1] - 1
r = size[-1] * 2
while r - l > 1:
	m = (r + l) // 2
	(x1, x2) = (0, len(size) - 1)
	cnt = 0
	while x1 <= x2:
		if size[x1] + size[x2] <= m:
			x1 += 1
			x2 -= 1
		else:
			x2 -= 1
		cnt += 1
	if cnt <= k:
		r = m
	else:
		l = m
print(r)


(n, k) = [int(x) for x in input().split()]
t = 2 * k
a = [0 for x in range(t - n)] + [int(x) for x in input().split()]
ans = 0
for i in range(t):
	ans = max(ans, a[i] + a[t - i - 1])
print(ans)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k >= n:
	print(max(l))
else:
	sum = max(l)
	l = l[:2 * (n - k)]
	for i in range(len(l)):
		sum = max(l[i] + l[-(i + 1)], sum)
	print(sum)


import sys
input = sys.stdin.readline
read = lambda : map(int, input().split())
read_float = lambda : map(float, input().split())

def ceil(x):
	if x != int(x):
		x = int(x) + 1
	return x

def factorial(x, m):
	val = 1
	while x > 0:
		val = val * x % m
		x -= 1
	return val

def fact(x):
	val = 1
	while x > 0:
		val *= x
		x -= 1
	return val

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // math.gcd(a, b)

def nCr(n, k):
	if k > n:
		return 0
	if k > n - k:
		k = n - k
	res = 1
	for i in range(k):
		res = res * (n - i)
		res = res / (i + 1)
	return int(res)

def primefs(n):
	primes = {}
	while n % 2 == 0 and n > 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0 and n > 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	p = x
	while p != link[p]:
		p = link[p]
	while x != p:
		nex = link[x]
		link[x] = p
		x = nex
	return p

def union(x, y, link, size):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	(prime[0], prime[1]) = (False, False)
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime

def phi(n):
	result = n
	p = 2
	while p * p <= n:
		if n % p == 0:
			while n % p == 0:
				n = n // p
			result = result * (1.0 - 1.0 / float(p))
		p = p + 1
	if n > 1:
		result = result * (1.0 - 1.0 / float(n))
	return int(result)

def is_prime(n):
	if n == 0:
		return False
	if n == 1:
		return True
	for i in range(2, int(n ** (1 / 2)) + 1):
		if not n % i:
			return False
	return True
MAXN = int(100000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i
spf = [0 for i in range(MAXN)]

def factoriazation(x):
	res = []
	for i in range(2, int(x ** 0.5) + 1):
		while x % i == 0:
			res.append(i)
			x //= i
	if x != 1:
		res.append(x)
	return res

def factors(n):
	res = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			res.append(i)
			res.append(n // i)
	return list(set(res))

def int_array():
	return list(map(int, input().strip().split()))

def float_array():
	return list(map(float, input().strip().split()))

def str_array():
	return input().strip().split()

def binary_search(low, high, w, h, n):
	while low < high:
		mid = low + (high - low) // 2
		if check(mid, w, h, n):
			low = mid + 1
		else:
			high = mid
	return low

def check(l, ps, n, t):
	for i in range(n - l + 1):
		if ps[i + l] - ps[i] <= t:
			return True
	return False
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
from itertools import permutations
import math
import bisect as bis
import random
import sys

def solve():
	(n, k) = read()
	sizes = list(read())
	if k >= n:
		print(sizes[-1])
		return
	one_wale = 2 * k - n
	m = sizes[-1]
	for i in range(n - one_wale):
		m = max(m, sizes[i] + sizes[-one_wale - 1 - i])
	print(m)
for _ in range(1):
	solve()


def main():
	(n, k) = map(int, input().split())
	l = list(map(int, input().split()))
	for (i, x) in zip(range((n - k) * 2 - 1, n - k - 1, -1), l):
		l[i] += x
	print(max(l))
main()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
b = [0] * k
for i in range(n - 1, -1, -1):
	b[(n - 1 - i) % k] += a[i]
	if n - 1 - i == k - 1:
		b = b[::-1]
print(max(b))


(num_cows, num_boxes) = list(map(int, input().split()))
cows = list(map(int, input().split()))
need = cows[-1]
limit = 2 * (num_cows - num_boxes)
for left in range(limit):
	right = limit - 1 - left
	if right < left:
		break
	need = max(need, cows[left] + cows[right])
print(need)


from collections import defaultdict, deque, Counter, OrderedDict
from bisect import insort, bisect_right, bisect_left
import threading, sys

def main():
	(n, k) = map(int, input().split())
	s = [int(i) for i in input().split()]
	n = n - (2 * k - n)
	if n <= 0:
		print(s[-1])
	else:
		ans = s[-1]
		for i in range(0, n // 2):
			ans = max(ans, s[i] + s[n - 1 - i])
		print(ans)
thread = threading.Thread(target=main)
thread.start()


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	i = n - 1
	ans = 0
	for j in range(2 * k - n):
		ans = max(ans, a[i])
		i -= 1
	start = 0
	while start < i:
		ans = max(ans, a[i] + a[start])
		i -= 1
		start += 1
	print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
total = 0
s.sort()
s.reverse()
if k >= n:
	print(s[0])
	exit()
x = n - k
y = k - x
for it in range(y):
	if s[it] > total:
		total = s[it]
ij = -1
for it in range(y, k):
	total = max(total, s[it] + s[ij])
	ij -= 1
print(total)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if k >= n:
	print(a[-1])
else:
	start = n - k
	maximum = a[-1]
	for i in range(n - k):
		maximum = max(maximum, a[start + i] + a[start - 1 - i])
	print(maximum)


import math
(n, k) = map(int, input().split())
arr = [int(z) for z in input().split()]
if k >= n:
	print(max(arr))
	exit()
if n == 1:
	print(arr[0])
	exit()
singles = 2 * k - n
pairedup = arr[:n - singles]
ans = arr[-1]
for i in range(len(pairedup) // 2):
	ans = max(pairedup[i] + pairedup[-1 * i - 1], ans)
print(ans)


(n, k) = map(int, input().split(' '))
l = list(map(int, input().split(' ')))
li = []
for i in range(n - k - 1 + 1):
	li.append(l[i] + l[2 * (n - k - 1) + 1 - i])
if len(li) == 0:
	print(l[n - 1])
else:
	print(max(max(li), l[n - 1]))


(n, k) = list(map(int, input().split()))
L = list(map(int, input().split()))
i = 0
p = 0
z = 1
R = [0 for _ in range(k)]
while i < n:
	R[p] += L[n - 1 - i]
	p = p + z
	i += 1
	if p == k or p == -1:
		z = z * -1
		if p == k:
			p = p - 1
		else:
			p = p + 1
print(max(R))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k >= n:
	print(l[n - 1])
else:
	one = 2 * k - n
	s = -1
	sum = -1
	if one >= 1:
		s = l[n - 1]
		idx = n - one
		l = [l[i] for i in range(idx)]
		for i in range(idx // 2):
			p = l[i] + l[idx - i - 1]
			if p > sum:
				sum = p
	else:
		for i in range(n // 2):
			p = l[i] + l[n - i - 1]
			if p > sum:
				sum = p
	if sum >= s:
		print(sum)
	else:
		print(s)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
lst = s[n - k:(n - k) * 2]
lst.reverse()
res = s[-1]
for i in range(n - k):
	res = max(res, lst[i] + s[i])
print(res)


import sys
oo = 1000000000000000
ar = []
(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
ar.sort()
(start, end, add) = (0, oo, n - k)
for i in range(n):
	if start < ar[i]:
		start = ar[i]
for i in range(n - k):
	end = ar[i] + ar[(add << 1) - 1 - i]
	if end > start:
		start = end
print(start)


(n, k) = map(int, input().split())
s_list = list(map(int, input().split()))
a_list = s_list[:n - min(n, 2 * k - n)]
b_list = reversed(a_list)
c_list = [a + b for (a, b) in zip(a_list, b_list)]
print(max(max(c_list or [0]), max(s_list)))


import sys
line1 = sys.stdin.readline().split()
n = int(line1[0])
k = int(line1[1])
s = sys.stdin.readline().split()
s = [int(x) for x in s]
if n == 1:
	print(s[0])
else:
	pairs = s[:2 * n - 2 * k]
	pair_sums = []
	for i in range(int(len(pairs) / 2)):
		pair_sums.append(pairs[i] + pairs[-i - 1])
	if len(pair_sums) > 0:
		pmax = max(pair_sums)
	else:
		pmax = 0
	singles = s[-(2 * k - n):]
	if len(singles) > 0:
		smax = max(singles)
	else:
		smax = 0
	print(max(pmax, smax))


def main():
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	minSize = s[n - 1]
	if n <= k:
		print(minSize)
		return
	i = 0
	total = n - 1
	while 2 * k > n:
		(n, k) = (n - 1, k - 1)
	for i in range(k):
		minSize = max(minSize, s[i] + s[n - i - 1])
	print(minSize)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
s.sort()
c = n - k
if c <= 0:
	print(s[-1])
else:
	L = [s[i] + s[2 * c - 1 - i] for i in range(c)]
	print(max(s[-1], max(L)))


import itertools, functools, math

def solve(n, k, s):
	if n <= k:
		return s[-1]
	needed = n
	pairs = 0
	while needed > k:
		needed -= 1
		pairs += 1
	size = s[-1]
	for i in range(pairs):
		size = max(size, s[i] + s[2 * pairs - 1 - i])
	return size
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
print(solve(n, k, s))


(num_cowbells, num_boxes) = [int(x) for x in input().split()]
sizes = [int(x) for x in input().split()]
if num_cowbells < num_boxes:
	print(max(sizes))
else:
	boxes = [0] * num_boxes
	for i in range(len(boxes)):
		boxes[i] += sizes[len(sizes) - 1 - i]
	for i in range(len(sizes) - len(boxes)):
		boxes[len(boxes) - i - 1] += sizes[len(sizes) - len(boxes) - i - 1]
	print(max(boxes))


def minSizeBox(N, B, sizes):
	if B >= N:
		return sizes[N - 1]
	maxSoFar = sizes[N - 1]
	k = 1
	i = 0
	while k < N:
		i = N - 2 * k
		if i + k <= B:
			break
		k += 1
	end = N - 1 - i
	start = 0
	while start < end:
		maxSoFar = max(sizes[start] + sizes[end], maxSoFar)
		start += 1
		end -= 1
	return maxSoFar
(cb, boxes) = input().split()
(cb, boxes) = (int(cb), int(boxes))
sizes = input().split()
sizes = [int(x) for x in sizes]
minSize = minSizeBox(cb, boxes, sizes)
print(minSize)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))[::-1]
high = arr[0]
for i in range(k, n):
	high = max(high, arr[i] + arr[2 * k - i - 1])
print(high)


(n, k) = map(int, input().split())
sizes = list(map(int, input().split()))

def solve(n, k, sizes):
	if k >= n:
		return max(sizes)
	head = sizes[:n - k]
	tail = sizes[n - k:]
	for (i, h) in enumerate(head[::-1]):
		tail[i] += h
	return max(tail)
print(solve(n, k, sizes))


import math

def needed_box(size):
	current_count_box = 0
	(i, j) = (0, number_of_cowbells - 1)
	while i < j:
		if list_cowbells[i] + list_cowbells[j] <= size:
			i += 1
			j -= 1
		elif list_cowbells[j] <= size:
			j -= 1
		else:
			return int(1000000000.0)
		current_count_box += 1
	return current_count_box if i > j else current_count_box + 1
(number_of_cowbells, number_of_box) = map(int, input().strip().split(' '))
list_cowbells = list(map(int, input().strip().split(' ')))
if number_of_cowbells == 1:
	print(list_cowbells[0])
else:
	(left, right) = (0, list_cowbells[-1] + list_cowbells[-2])
	while left < right:
		middle = math.ceil((right + left + 1) / 2)
		number_of_needed_box = needed_box(middle)
		if number_of_needed_box > number_of_box:
			left = middle
		elif number_of_needed_box <= number_of_box:
			right = middle - 1
	print(right + 1)


read = lambda : map(int, input().split())
(n, k) = read()
S = list(read())

def bin(L, R):
	while R - L > 1:
		M = (R + L) // 2
		if f(M):
			R = M
		else:
			L = M
	return R

def f(s):
	l = 0
	r = n - 1
	cnt = 0
	while r - l > 0:
		if S[r] + S[l] <= s:
			l += 1
		if S[r] <= s:
			r -= 1
		cnt += 1
	if r - l == 0:
		cnt += 1
	if cnt > k:
		return False
	return True
ans = bin(S[-1] - 1, 10 ** 9)
print(ans)


from collections import deque
(n, k) = map(int, input().split())
a = deque(map(int, input().split()))
if k >= n:
	print(max(a))
else:
	ret = -float('inf')
	for _ in range(2 * k - n):
		v = a.pop()
		ret = max(ret, v)
	for i in range(len(a) // 2):
		ret = max(ret, a[i] + a[len(a) - i - 1])
	print(ret)


import sys
lines = sys.stdin.readlines()
(n, k) = map(int, lines[0].split())
s = list(map(int, lines[1].split()))
if k == 1:
	if n == 1:
		print(s[0])
	else:
		print(s[0] + s[1])
	sys.exit(0)
scene1 = s[-1]
left_boxes = k - 1
left_numbers = n - 1
small = 0
end = n - 2
while small <= end:
	is_double = 2 * left_boxes <= left_numbers
	if s[small] + s[end] <= scene1:
		small += 1
		end -= 1
		left_boxes -= 1
		left_numbers -= 2
	elif is_double:
		scene1 = max(scene1, s[small] + s[end])
		small += 1
		end -= 1
	else:
		end -= 1
		left_boxes -= 1
		left_numbers -= 1
if 2 * k == n:
	scene1 = float('inf')
scene2 = s[0] + s[-1]
left_boxes = k - 1
left_numbers = n - 2
small = 1
end = n - 2
while small <= end:
	is_double = 2 * left_boxes <= left_numbers
	if s[small] + s[end] <= scene2:
		small += 1
		end -= 1
		left_boxes -= 1
		left_numbers -= 2
	elif is_double:
		scene2 = max(scene2, s[small] + s[end])
		small += 1
		end -= 1
	else:
		end -= 1
		left_boxes -= 1
		left_numbers -= 1
print(min(scene1, scene2))


def main():
	(n, k) = [int(i) for i in input().split()]
	ss = [int(i) for i in input().split()]
	end = ss[n - 1]
	if k >= n:
		print(end)
	else:
		s = 0
		e = 2 * (n - k) - 1
		mx = end
		while s < e:
			temp = ss[s] + ss[e]
			if temp > mx:
				mx = temp
			s += 1
			e -= 1
		print(mx)
main()


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
if k >= n:
	print(a[-1])
	exit()
m = a[-1]
for i in range(0, n - k):
	m = max(a[i] + a[2 * (n - k) - 1 - i], m)
print(m)


import math

def can_pack(m, b):
	global n, k
	cnt = 0
	if b[-1] > m:
		return False
	p1 = 0
	p2 = n - 1
	while p1 < p2:
		if b[p2] + b[p1] <= m:
			p1 += 1
			p2 -= 1
		else:
			p2 -= 1
		cnt += 1
	if p1 == p2:
		cnt += 1
	return cnt <= k
(n, k) = [int(x) for x in input().split()]
b = [int(x) for x in input().split()]
l = 0
r = 10 ** 9
while l != r - 1:
	m = (l + r) // 2
	if not can_pack(m, b):
		l = m
	else:
		r = m
print(r)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
t = k - (2 * k - n)
res = 0
for i in range(t):
	res = max(res, a[i] + a[2 * t - 1 - i])
res = max(res, a[n - 1])
print(res)


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
arr.reverse()
idx = 0
ans = 0
while idx < n and n - idx - 1 <= (k - 1) * 2:
	ans = max(ans, arr[idx])
	idx += 1
	k -= 1
left = idx
right = n - 1
while left < right:
	ans = max(arr[left] + arr[right], ans)
	left += 1
	right -= 1
print(ans)


def count(arr, n, key):
	(res, i, j) = (0, 0, n - 1)
	while i <= j:
		res += 1
		if i < j and arr[i] + arr[j] <= key:
			i += 1
			j -= 1
		else:
			i += 1
	return res

def binary_search(arr, n, key):
	l = arr[0]
	r = l << 1
	while l != r:
		mid = l + r >> 1
		if count(arr, n, mid) <= key:
			r = mid
		else:
			l = mid + 1
	return l

def main():
	(n, k) = map(int, input().split())
	a = list(map(int, input().split()))[::-1]
	print(binary_search(a, n, k))
main()


import math
(m, n) = map(int, input().split())
a = list(map(int, input().split()))
b = a.copy()
if n >= m:
	print(max(a))
else:
	arr = [0 for j in range(n)]
	ptr = 0
	ptr1 = 2 * (m - n) - 1
	while ptr1 > ptr:
		b[ptr1] = a[ptr1] + a[ptr]
		ptr += 1
		ptr1 -= 1
	print(max(b))


(n, k) = map(int, input().split(' '))
s = list(map(int, input().split(' ')))
result = s[-1]
while k * 2 > n:
	n -= 1
	k -= 1
if n > 0:
	for i in range(int(n / 2)):
		result = max(result, s[i] + s[n - 1 - i])
print(result)


I = lambda : list(map(int, input().split()))
(n, k) = I()
a = I()
n -= k
print([a[-1], max([a[i] + a[n * 2 - i - 1] for i in range(n)] + [a[-1]])][n > 0])


(no_of_cowbell, no_of_boxe) = map(int, input().split())
li1 = list(map(int, input().split()))
cows_packed = no_of_boxe * 2
if no_of_cowbell <= no_of_boxe:
	print(li1[no_of_cowbell - 1])
else:
	j = no_of_cowbell - 1
	ans = li1[no_of_cowbell - 1]
	if no_of_cowbell - no_of_boxe > 0:
		j = (no_of_cowbell - no_of_boxe) * 2 - 1
	i = 0
	while i < j:
		if li1[i] + li1[j] > ans:
			ans = li1[i] + li1[j]
		i += 1
		j -= 1
	print(ans)


(a, b) = map(int, input().split())
s = list(map(int, input().split()))
s = [-1] + s
if a <= b:
	print(s[a])
else:
	sol = s[a]
	for i in range(a - b):
		x = s[a - b - i] + s[a - b + 1 + i]
		if x > sol:
			sol = x
	print(sol)


a = list(map(int, input().split(' ')))
(n, k) = (a[0], a[1])
s = list(map(int, input().split(' ')))
if k >= n:
	m = max(s)
else:
	(r, i) = (2 * (n - k), 0)
	m = max(s[r - 1:])
	while True:
		r -= 1
		m = max(s[i] + s[r], m)
		i += 1
		if r <= i:
			break
print(m)


(n, k) = [int(i) for i in input().split()]
a = [int(i) for i in input().split()]
b = []
for i in range(min(k, len(a))):
	b.append(a.pop())
for i in range(min(n - k, len(a))):
	b[k - i - 1] += a.pop()
print(max(b))


(n, k) = [int(i) for i in input().split()]
sizes = [int(i) for i in input().split()]
if k >= n:
	print(max(sizes))
else:
	x1 = sizes[-1]
	sizes = sizes[:2 * (n - k)]
	x2 = max([a + b for (a, b) in zip(sizes, sizes[::-1])])
	print(max(x1, x2))


(n, k) = map(int, input().split())
l1 = list(map(int, input().split()))
l1.sort()
l2 = []
if k >= n:
	print(max(l1))
else:
	for i in range(n - 1, 2 * (n - k) - 1, -1):
		l2.append(l1[i])
	for i in range(n - k):
		l2.append(l1[i] + l1[2 * (n - k) - 1 - i])
	print(max(l2))


__author__ = 'Utena'
(n, k) = list(map(int, input().split()))
s = list(map(int, input().split()))
t = s[-1]
for i in range(len(s) - k):
	if s[i] + s[2 * (len(s) - k) - 1 - i] > t:
		t = s[i] + s[2 * (len(s) - k) - 1 - i]
print(t)


(N, k) = list(map(int, input().split(' ')))
s = list(map(int, input().split(' ')))
n = (N - k) * 2
ans = s[-1]
for i in range(N - k):
	ans = max(ans, s[i] + s[n - 1 - i])
print(ans)


(n, k) = [int(x) for x in input().split()]
s = [int(x) for x in input().split()]
t = []
proper = n - k
t.append(s[-1])
for i in range(proper):
	t.append(s[i] + s[2 * proper - i - 1])
print(max(t))


class CodeforcesTask604BSolution:

	def __init__(self):
		self.result = ''
		self.n_k = []
		self.boxes = []

	def read_input(self):
		self.n_k = [int(x) for x in input().split(' ')]
		self.boxes = [int(x) for x in input().split(' ')]

	def process_task(self):
		x = 2 * (self.n_k[0] - self.n_k[1])
		boxed = []
		for y in range(x // 2):
			boxed.append(self.boxes[y] + self.boxes[x - y - 1])
		if x > 0:
			self.result = str(max(self.boxes[-1], max(boxed)))
		else:
			self.result = str(self.boxes[-1])

	def get_result(self):
		return self.result
Solution = CodeforcesTask604BSolution()
Solution.read_input()
Solution.process_task()
print(Solution.get_result())


import itertools as it
import functools
import operator
import collections
import math
import sys

def solve(xs, n, k):
	if k >= n:
		return max(xs)
	ys1 = xs[:n - k]
	ys2 = xs[n - k:2 * (n - k)]
	maxval = max((a + b for (a, b) in zip(ys1, ys2[::-1])))
	return max(maxval, xs[-1])

def main():
	(n, k) = list(map(int, input().split()))
	xs = [int(c) for c in input().split()]
	assert len(xs) == n
	result = solve(xs, n, k)
	print(result)

def __starting_point():
	main()
__starting_point()


(n, k) = map(int, input().split())
s = [int(i) for i in input().split()]
max_ = s[n - 1]
for i in range(n - k):
	max_ = max(max_, s[i] + s[2 * (n - k) - i - 1])
print(max_)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
Max = A[-1]
while 2 * k > len(A) and A != []:
	del A[-1]
	k -= 1
while A != []:
	Max = max(Max, A[0] + A[-1])
	del A[0], A[-1]
print(Max)


a = input().split()
b = input().split()
d = int(a[0])
e = int(a[1])
for i in range(d):
	b[i] = int(b[i])
if d > e:
	max1 = b[-1]
	while e > d // 2:
		e -= 1
		d -= 1
		del b[-1]
	for i in range(d // 2):
		g = b[i] + b[-(i + 1)]
		if g > max1:
			max1 = g
	print(max1)
else:
	print(b[-1])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
l.reverse()
y = n - k
x = k + k - n
m = max(l)
l = l[x:]
n = len(l)
for i in range(n // 2):
	m = max(l[i] + l[n - 1 - i], m)
print(m)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
if n <= k:
	print(max(a))
else:
	m = a[-1]
	for i in range(0, n - k):
		m = max(m, a[i] + a[2 * (n - k) - i - 1])
	print(m)


(n, k) = list(map(int, input().split(' ')))
thing = input()
thing = thing.split(' ')
balls = []
for t in thing:
	balls += [int(t)]
if n <= k:
	m = max(balls)
else:
	squeeze = n - k
	m = 0
	for i in range(squeeze):
		current = balls[i] + balls[2 * squeeze - 1 - i]
		m = max(current, m)
	m = max(balls[n - 1], m)
print(m)


(n, k) = map(int, input().split())
a = [int(s) for s in input().split()]
p = n - k
q = 2 * k - n
if n < k:
	q = n
	p = 0
ma = 0
for i in range((n - q) // 2):
	ma = max(a[i] + a[n - q - i - 1], ma)
ma2 = 0
for i in range(n - q, n):
	ma2 = max(a[i], ma2)
print(max(ma, ma2))


def score(value, time, wrongAnswer):
	return max(0.3 * value, (1 - time / 250.0) * value - 50 * wrongAnswer)

def actualScore():
	times = input().split()
	times = list(map(int, times))
	wrongAnswer = input().split()
	wrongAnswer = list(map(int, wrongAnswer))
	temp = input().split()
	temp = list(map(int, temp))
	total = 0
	for problem in range(len(times)):
		total += score(500 * (problem + 1), times[problem], wrongAnswer[problem])
	total += 100 * int(temp[0])
	total -= 50 * int(temp[1])
	return int(total)

def maxPair(theList):
	theMax = 0
	for index in range(int(len(theList) / 2)):
		if theList[index] + theList[len(theList) - 1 - index] > theMax:
			theMax = theList[index] + theList[len(theList) - 1 - index]
	return theMax

def cowBox():
	temp = input().split()
	bells = int(temp[0])
	box = int(temp[1])
	temp = input().split()
	sizes = list(map(int, temp))
	if box >= bells:
		return sizes[len(sizes) - 1]
	if box == bells / 2.0:
		return maxPair(sizes)
	else:
		return max(maxPair(sizes[:len(sizes) - (2 * box - bells)]), sizes[len(sizes) - 1])
print(cowBox())


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
ans = 0
m = 2 * k - n
if m > 0:
	for i in range(m):
		try:
			ans = max(ans, s[-1])
			s.pop(-1)
			n -= 1
		except:
			break
for i in range(n // 2):
	ans = max(ans, s[i] + s[n - i - 1])
print(ans)


from sys import stdin
(n, k) = stdin.readline().rstrip().split(' ')
n = int(n)
k = int(k)
k = min(k, n)
s = stdin.readline().rstrip().split(' ')
s = [int(ss) for ss in s]
s = [int(ss) for ss in s]
max_size = 0
pairs = n - k
for i in range(pairs):
	max_size = max(max_size, s[i] + s[2 * pairs - 1 - i])
for i in range(2 * pairs, n):
	max_size = max(max_size, s[i])
print(max_size)


(n, k) = list(map(int, input().split()))
s = list(map(int, input().split()))
maxi = 0
pos = n - 1
if n == 1:
	print(s[0])
elif k >= n:
	print(s[-1])
else:
	while 2 * (k - 1) >= n - 1:
		maxi = max(maxi, s[pos])
		pos -= 1
		k -= 1
		n -= 1
	posq = 0
	while pos - posq >= 1:
		maxi = max(maxi, s[posq] + s[pos])
		pos -= 1
		posq += 1
	if pos == posq:
		maxi = max(maxi, s[pos])
	print(maxi)


from sys import stdin

def main():
	nextint = map(int, stdin.read().split()).__next__
	(n, k) = (nextint(), nextint())
	s = [nextint() for _ in range(n)]
	print(max([s[x] + s[y] for (x, y) in zip(range(n - k - 1, -1, -1), range(n - k, n))] + [s[-1]]))
main()


(n, k) = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
couples = n - k
size = 0
if 2 * k - n > 0:
	size = s[n - 1]
for i in range(2 * couples - 1, -1, -1):
	size = max(size, s[i] + s[2 * couples - i - 1])
print(size)


R = lambda : map(int, input().split())
F = lambda : [int(x) for x in input().split()]
(n, k) = R()
s = F()
x = n - k
if k >= n:
	print(s[n - 1])
else:
	l = 2 * (n - k)
	maxi = 0
	for i in range(l // 2):
		maxi = max(maxi, s[i] + s[l - i - 1])
	if l % 2 != 0:
		maxi = max(maxi, s[l // w])
	print(max(maxi, s[n - 1]))


import sys
input_file = sys.stdin
(cow_bells, boxes) = map(int, input_file.readline().rstrip().split())
sizes = list(map(int, input_file.readline().rstrip().split()))
if boxes >= cow_bells:
	print(max(sizes))
else:
	boxes_stats = sizes[cow_bells - boxes:]
	sizes = list(reversed(sizes[:cow_bells - boxes]))
	for (i, size) in enumerate(sizes):
		boxes_stats[i] += sizes[i]
	print(max(boxes_stats))


def can(s, m, k):
	need = 0
	l = 0
	r = len(s) - 1
	while l <= r:
		if s[r] + s[l] <= m:
			need += 1
			r -= 1
			l += 1
		else:
			need += 1
			r -= 1
	return need <= k
(n, k) = (int(x) for x in input().split())
s = [int(x) for x in input().split()]
res = s[-1] - 1
step = 2 ** 30
while step:
	m = res + step
	if not can(s, m, k):
		res += step
	step //= 2
print(res + 1)


(n, k) = list(map(int, input().split()))
s = list(map(int, input().split()))
(i, o, r, e) = (n - 1, k, s[n - 1], 0)
while (o - 1) * 2 >= i:
	(o, i) = (o - 1, i - 1)
while e < i:
	r = max(r, s[e] + s[i])
	(e, i) = (e + 1, i - 1)
print(r)


(n, k) = list(map(int, input().split()))
arr = list(map(int, input().split()))
x = max(n - k, 0)
if x == 0:
	print(arr[-1])
	exit()
res = arr[-1]
for i in range(x):
	res = max(res, arr[i] + arr[2 * x - i - 1])
print(res)


(n, k) = map(int, input().split())
S = list(map(int, input().split()))
t = n - k
m = 0
for i in range(n):
	if i < t:
		s = S[i] + S[2 * t - 1 - i]
	elif i < 2 * t:
		continue
	else:
		s = S[i]
	if s > m:
		m = s
print(m)


from sys import stdin, stdout
nmbr = lambda : int(stdin.readline())
lst = lambda : list(map(int, stdin.readline().split()))
for _ in range(1):
	(n, k) = lst()
	a = lst()
	boxes = [0] * k
	p = 0
	p1 = n - 1
	while p < k and p1 >= 0:
		boxes[p] += a[p1]
		p += 1
		p1 -= 1
	p -= 1
	while p1 >= 0 and p >= 0:
		boxes[p] += a[p1]
		p -= 1
		p1 -= 1
	print(max(boxes))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if n <= k:
	print(l[-1])
elif k == 1:
	print(sum(l))
else:
	s = n - k
	if s == 1:
		print(max(l[-1], l[0] + l[1]))
	else:
		c = []
		i = 0
		j = 2 * s - 1
		while i < j:
			c.append(l[i] + l[j])
			i += 1
			j -= 1
		if s == k:
			print(max(c))
		else:
			print(max(l[-1], max(c)))


(n, k) = input().split()
n = int(n)
k = int(k)
s = input().split()
for i in range(n):
	s[i] = int(s[i])
r = (n - k) * 2
m = s[-1]
i = 0
if k >= n:
	print(m)
else:
	while i < r:
		x = s[i] + s[r - i - 1]
		if m < x:
			m = x
		i += 1
	print(m)


a = list(map(int, input().split()))
(n, k) = (a[0], a[1])
l = k
bells = list(map(int, input().split()))
mymax = bells[-1]
while l > n / 2 and l > 1 and (n > 1):
	del bells[-1]
	l -= 1
	n -= 1
while n > 1:
	mymax = max(mymax, bells[0] + bells[-1])
	del bells[0]
	del bells[-1]
	n -= 2
if len(bells) > 0:
	mymax = max(mymax, bells[0])
print(mymax)


from sys import stdin, stdout
from math import gcd, ceil
ii1 = lambda : int(stdin.readline().strip())
is1 = lambda : stdin.readline().strip()
iia = lambda : list(map(int, stdin.readline().strip().split()))
isa = lambda : stdin.readline().strip().split()
mod = 1000000007
(n, k) = iia()
arr = [0] * (2 * k - n) + iia()
res = 0
(l, r) = (0, 1)
for i in range(len(arr) // 2):
	(a, b) = (arr[l], arr[-r])
	res = max(res, a + b)
	l += 1
	r += 1
print(res)


import unittest
import sys

class Cowbell:

	def __init__(self, test_inputs=None):
		it = iter(test_inputs.split('\n')) if test_inputs else None

		def uinput():
			return next(it) if it else sys.stdin.readline().rstrip()
		[self.n, self.k] = list(map(int, uinput().split()))
		self.nums = list(map(int, uinput().split()))

	def calculate(self):
		b = self.nums[self.n - self.k:]
		for i in range(self.n - self.k):
			b[i] += self.nums[self.n - self.k - 1 - i]
		result = max(b)
		return str(result)

class unitTests(unittest.TestCase):

	def test_single_test(self):
		test = '2 1\n2 5'
		d = Cowbell(test)
		self.assertEqual(d.n, 2)
		self.assertEqual(d.k, 1)
		self.assertEqual(d.nums, [2, 5])
		self.assertEqual(Cowbell(test).calculate(), '7')
		test = '4 3\n2 3 5 9'
		self.assertEqual(Cowbell(test).calculate(), '9')
		test = '3 2\n3 5 7'
		self.assertEqual(Cowbell(test).calculate(), '8')
		test = ''

	def time_limit_test(self, nmax):
		import random
		import timeit
		test = str(nmax) + ' ' + str(nmax) + '\n'
		numnums = [str(i) + ' ' + str(i + 1) for i in range(nmax)]
		test += '\n'.join(numnums) + '\n'
		nums = [random.randint(1, 10000) for i in range(nmax)]
		test += ' '.join(map(str, nums)) + '\n'
		start = timeit.default_timer()
		d = Cowbell(test)
		calc = timeit.default_timer()
		d.calculate()
		stop = timeit.default_timer()
		print('\nTimelimit Test: ' + '{0:.3f}s (init {1:.3f}s calc {2:.3f}s)'.format(stop - start, calc - start, stop - calc))

def __starting_point():
	sys.setrecursionlimit(100000)
	if sys.argv[-1] == '-ut':
		unittest.main(argv=[' '])
	sys.stdout.write(Cowbell().calculate())
__starting_point()


(n, k) = input().split()
(n, k) = (int(n), int(k))
ding = [int(i) for i in input().split()]
a = 2 * k - n
s = 0
if a != 0:
	s = ding[-1]
	ding = ding[:-a]
for i in range(k - a):
	if ding[i] + ding[-i - 1] > s:
		s = ding[i] + ding[-i - 1]
print(s)


(n, k) = [int(elem) for elem in input().split(' ')]
sizes = [int(elem) for elem in input().split(' ')]
if n <= k:
	print(sizes[-1])
else:
	boxes = sizes[n - k:]
	for i in range(n - k):
		boxes[i] += sizes[n - k - i - 1]
	print(max(boxes))


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
end = 2 * (n - k) - 1
start = 0
mx = l[-1]
while start < end:
	if l[start] + l[end] > mx:
		mx = l[start] + l[end]
	start += 1
	end -= 1
print(mx)


(n, k) = map(int, input().split())
s = [int(x) for x in input().split()]
ans = 0
if k >= n:
	print(max(s))
else:
	while n // 2 < k:
		ans = max(ans, s.pop())
		k -= 1
		n -= 1
	(i, j) = (0, len(s) - 1)
	while i < j:
		ans = max(ans, s[i] + s[j])
		i += 1
		j -= 1
	print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
extra = 2 * k - n
max1 = -1
for i in range((n - extra) // 2):
	sum1 = s[i] + s[n - extra - 1 - i]
	if sum1 > max1:
		max1 = sum1
print(max(max1, s[-1]))


import io
import math
(n, m) = map(int, input().split())
lima = sorted(map(int, input().split()))
mike = lima[-1]
if m >= n:
	print(mike)
else:
	kite = 2 * m - n
	for i in range((n - kite) // 2):
		j = n - kite - 1 - i
		t = lima[i] + lima[j]
		if t > mike:
			mike = t
	print(mike)


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
if k >= n:
	print(l[n - 1])
	exit()
single = n - k
double = 2 * k - n
ans = 0
for i in range(n - 1, 2 * n - 2 * k - 1, -1):
	if l[i] > ans:
		ans = l[i]
for i in range(n - k):
	t = l[i] + l[2 * n - 2 * k - 1 - i]
	if t > ans:
		ans = t
print(ans)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
x = s[-1]
if k < n:
	y = 2 * (n - k) - 1
	for i in range(n - k):
		x = max(x, s[i] + s[y - i])
print(x)


(n, k) = map(int, input().split())
S = list(map(int, input().split()))
x = 2 * k - n
if n - x > 0:
	U = S[:n - x]
	ans = max(S)
	for i in range(len(U) // 2 + 1):
		ans = max(ans, U[i] + U[len(U) - i - 1])
	print(ans)
else:
	print(max(S))


import sys
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
a = s[-k:]
ans = max(a)
o = 0
for i in range(n - k - 1, -1, -1):
	a[o] += s[i]
	ans = max(ans, a[o])
	o += 1
print(ans)


(n, k) = map(int, input().split())
a = [int(x) for x in input().split()]

def bs(s):
	c = 0
	left = 0
	right = n - 1
	while left <= right:
		c += 1
		if left == right:
			break
		if a[left] + a[right] <= s:
			left += 1
			right -= 1
		else:
			right -= 1
	if c <= k:
		return True
	else:
		return False
(l, h) = (max(a), 10 ** 10)
while l <= h:
	m = l + (h - l) // 2
	if bs(m):
		ans = m
		h = m - 1
	else:
		l = m + 1
print(ans)


def size(n, k, s):
	if n <= k:
		return s[-1]
	p = n - k
	return max(s[-1], max((s[i] + s[2 * p - i - 1] for i in range(p))))
(n, k) = map(int, input().split())
s = list(map(int, input().split()))
print(size(n, k, s))


(n, k) = map(int, input().split())
lis = list(map(int, input().split()))
m = 0
aa = (n - k) * 2
for i in range(0, aa // 2):
	lis[aa - i - 1] += lis[i]
print(max(lis))


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
finall = []
sp = n - k
if sp > 0:
	a1 = s[0:sp]
	a2 = s[sp:sp * 2]
	for i in range(0, sp):
		finall.append(a1[i] + a2[-(i + 1)])
	print(max(finall + s[sp * 2:]))
else:
	print(s[-1])


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
(l, r, m) = (max(s) - 1, 2000000, -1)
while r - l > 1:
	m = (l + r) // 2
	(p, used) = (0, 0)
	for i in range(n - 1, -1, -1):
		if i < p:
			break
		elif s[p] + s[i] <= m:
			p += 1
		used += 1
	if used <= k:
		r = m
	else:
		l = m
print(r)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = 2 * k - n
b = a[:n - x]
anss = a[n - x:]
for i in range(len(b) // 2):
	anss.append(b[i] + b[len(b) - i - 1])
print(max(anss))


def contains(list, count, v):
	last = len(list) - 1
	first = 0
	while first <= last:
		if count <= 0:
			return False
		t = v
		kil = 0
		if (last - first + 1) // 2 > count:
			return False
		while kil < 2 and last >= first and (t >= list[last]):
			kil += 1
			t -= list[last]
			last -= 1
		while kil < 2 and first <= last and (t >= list[first]):
			kil += 1
			t -= list[first]
			first += 1
		count -= 1
	return True
(n, k) = [int(x) for x in input().split(' ')]
list = [int(x) for x in input().split(' ')]
l = list[-1]
r = sum(list)
while l < r:
	middle = (l + r) // 2
	if contains(list, k, middle):
		r = middle
	else:
		l = middle + 1
print(l)


inp = input().split()
n = int(inp[0])
k = int(inp[1])
i = 0
array = []
result = 0
inp = input().split()
while i < n:
	array.append(int(inp[i]))
	i = i + 1
array.sort()
if n <= k:
	result = array[n - 1]
else:
	one = 2 * k - n
	len = n - one
	i = 0
	while i < len / 2:
		result = max(result, array[i] + array[len - 1 - i])
		i = i + 1
	i = len
	while i < n:
		result = max(result, array[i])
		i = i + 1
print(result)


(n, k) = map(int, input().split())
s = list(map(int, input().split()))
maxs = max(s)
secondHalf = s[n - k:n - k + n - k]
secondHalf.reverse()
for i in range(n - k):
	maxs = max(maxs, s[i] + secondHalf[i])
print(maxs)


import math
(n, k) = map(int, input().split())
data = list(map(int, input().split()))
colvo_1_cor = k * 2 - n
colvo_2_cor = k - colvo_1_cor
answer = []
if colvo_1_cor > n:
	colvo_1_cor = n
for i in range(colvo_1_cor):
	answer.append(data[-1])
	data.pop()
if len(data) > 0:
	index1 = 0
	index2 = len(data) - 1
	while index1 != len(data) // 2 + 1:
		answer.append(data[index1] + data[index2])
		index1 += 1
		index2 -= 1
print(max(answer))


(n, k) = list(map(int, input().split()))
ss = list(map(int, input().split()))
if k >= n:
	print(ss[n - 1])
else:
	top = 2 * (n - k) - 1
	bottom = 0
	m = ss[n - 1]
	while top > bottom:
		v = ss[top] + ss[bottom]
		if v > m:
			m = v
		bottom += 1
		top -= 1
	print(m)


t = input()
temp = t.split()
n = int(temp[0])
k = int(temp[1])
s = input()
temp = s.split()
cowbells = [int(i) for i in temp]
if k >= n:
	print(cowbells[n - 1])
else:
	singleBoxes = 2 * k - n
	doubleBoxes = 2 * (n - k)
	j = doubleBoxes - 1
	maximum = 0
	for i in range(doubleBoxes - 1):
		if i == j:
			break
		else:
			maximum = max(maximum, cowbells[i] + cowbells[j])
			j -= 1
	print(max(maximum, cowbells[n - 1]))


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from io import BytesIO, IOBase

def vsInput():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]

def possible(size):
	l = 0
	h = n - 1
	boxes = k
	while boxes > 0 and l <= h:
		if a[l] + a[h] <= size:
			l += 1
			h -= 1
		else:
			h -= 1
		boxes -= 1
	if l <= h:
		return False
	return True
(n, k) = value()
a = array()
if n == 1:
	print(a[0])
	exit()
low = a[-1]
high = low + a[-2]
while low <= high:
	mid = (low + high) // 2
	if possible(mid):
		ans = mid
		high = mid - 1
	else:
		low = mid + 1
print(ans)


(n, m) = map(int, input().split())
arr = list(map(int, input().split()))
mx = arr[-1]
for i in range(n - m):
	mx = max(mx, arr[i] + arr[2 * (n - m) - i - 1])
print(mx)


def main():
	(n, k) = (int(x) for x in input().split())
	L = [int(x) for x in input().split()]
	result = solver(L, k)
	print(result)

def solver(L, k):
	n = len(L)
	if k >= n:
		return L[len(L) - 1]
	else:
		maximum = L[len(L) - 1]
		pack2s = L[:2 * (n - k)]
		for i in range(n - k):
			size = pack2s[i] + pack2s[len(pack2s) - i - 1]
			if size > maximum:
				maximum = size
		return maximum
main()


import sys

def solve(n, m, x):
	if n == m:
		return x[n - 1]
	pares = 0
	while pares * 2 + (m - pares) < n:
		pares += 1
	maxi = x[n - 1]
	j = pares * 2 - 1
	for i in range(pares):
		maxi = max(maxi, x[i] + x[j - i])
	return maxi
x = [int(x) for x in input().split()]
n = x[0]
m = x[1]
x = [int(x) for x in input().split()]
print(solve(n, m, x))


import sys
(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
r = 0
i = n - 1
p = 0
if n // 2 == k:
	for i in range(0, n // 2):
		r = max(r, arr[i] + arr[n - 1 - i])
else:
	two = n - k
	one = k - two
	if two > 0:
		for i in range(0, two * 2):
			r = max(r, arr[i] + arr[two * 2 - i - 1])
	r = max(r, arr[n - 1])
print(r)


(bells, boxes) = map(int, input().split())
weights = list(map(int, input().split()))
heaviest = -1
while boxes > bells // 2 and bells > 0:
	heaviest = max(heaviest, weights[bells - 1])
	boxes -= 1
	bells -= 1
(i, j) = (0, bells - 1)
while i <= j:
	if i == j:
		heaviest = max(heaviest, weights[i])
	else:
		heaviest = max(heaviest, weights[i] + weights[j])
	i += 1
	j -= 1
print(heaviest)


z = input().split()
a = input().split()
n = int(z[0])
m = int(z[1])
s = int(a[n - 1])
for i in range(n - m):
	s = max(s, int(a[i]) + int(a[2 * n - 2 * m - i - 1]))
print(s)


(n, k) = map(int, input().split())
ar = list(map(int, input().split()))
ans = int(ar[n - 1])
i = int(0)
L = int(0)
R = int(n - (k + k - n) - 1)
while L < R:
	ans = max(ans, ar[L] + ar[R])
	L += 1
	R -= 1
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
x = k * 2 - n
x = n - x
ans = a[-1]
for i in range(x):
	ans = max(ans, a[i] + a[x - i - 1])
print(ans)


(n, k) = map(int, input().split())
arr = [int(x) for x in input().split()]
if k > n:
	print(arr[-1])
	exit(0)
val = n - k
val *= 2
mx = 0
for i in range(val):
	mx = max(mx, arr[i] + arr[val - i - 1])
for i in range(val, n):
	mx = max(mx, arr[i])
print(mx)


def read_ints():
	return map(int, input().strip().split())
(n, k) = read_ints()
s = list(read_ints())
if n <= k:
	print(max(s))
else:
	k1 = n - k
	k2 = 2 * k - n
	if k2 > 0:
		m2 = max(s[2 * k1:])
	else:
		m2 = 0
	m1 = max((a + b for (a, b) in zip(s[:k1], s[2 * k1 - 1:k1 - 1:-1])))
	print(max(m1, m2))


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
maxx = arr[-1]
for i in range(n - k):
	maxx = max(maxx, arr[i] + arr[2 * (n - k) - i - 1])
print(maxx)


(n, k) = [int(i) for i in input().split()]
nums = [int(i) for i in input().split()]
max_val = nums[-1]
for i in range(n - k):
	max_val = max(max_val, nums[i] + nums[2 * (n - k) - i - 1])
print(max_val)


from sys import stdin, exit, setrecursionlimit
from bisect import *
from itertools import permutations
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()
mod = 10 ** 9 + 7

def check(z):
	(a, b) = (0, n - 1)
	cnt = 0
	if s[b] > z:
		return False
	while a <= b:
		if a == b:
			a += 1
		elif s[a] + s[b] <= z:
			a += 1
			b -= 1
		elif s[b] > z or s[a] > z:
			return False
		else:
			b -= 1
		cnt += 1
	return cnt <= k
(n, k) = mi()
s = lmi()
l = 0
r = 2 * 10 ** 6 + 1
while l < r:
	mid = l + r >> 1
	if check(mid):
		r = mid
	else:
		l = mid + 1
print(l)


import os
import sys
from io import BytesIO, IOBase
mod = 10 ** 9 + 7

def main():
	(n, k) = map(int, input().split())
	s = list(map(int, input().split()))
	two = n - k
	l = 0
	r = 2 * two - 1
	ans = 0
	for _ in range(two):
		ans = max(ans, s[l] + s[r])
		l += 1
		r -= 1
	ans = max(ans, s[-1])
	print(ans)

def nouse0():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse1():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse2():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def nouse3():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse4():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')

def nouse5():
	a = 420
	b = 420
	print(f'i am nitish{(a + b) // 2}')
main()


(n, k) = (int(x) for x in input().split())
s = [int(x) for x in input().split()]
t = max(n - k, 0)
print(max([s[i] + s[2 * t - 1 - i] for i in range(t)] + s[2 * t:]))