Under construction

Still being built. Things may change

Best Subsequence

Time limit3sMemory limit512 MB

Summary
Pick k elements of an array in index order so that the largest sum of two cyclically adjacent chosen elements is as small as possible.
Level

Medium7 of 10

Topics
Binary search, Greedy, Dynamic programming
Solved
No attempts yet

Problem

You are given an array w1,w2,…,wnw_1, w_2, \ldots, w_n of length nn.

You need to choose a subsequence of kk elements. Let their indices be 1≤i1<i2<…<ik≤n1 \le i_1 < i_2 < \ldots < i_k \le n.

Your goal is to find the minimum possible value of

max⁡(wi1+wi2,wi2+wi3,…,wik−1+wik,wik+wi1)\max(w_{i_1} + w_{i_2}, w_{i_2} + w_{i_3}, \ldots, w_{i_{k-1}} + w_{i_k}, w_{i_k} + w_{i_1})

among all such subsequences.

Input

The first line contains two integers nn and kk (3≤k≤n≤2000003 \le k \le n \le 200000), the length of the array and the length of the subsequence.

The second line contains nn space-separated integers w1,w2,…,wnw_1, w_2, \ldots, w_n (1≤wi≤1091 \le w_i \le 10^9).

Output

Print one integer: the minimum possible value of the expression above over all subsequences of length kk.

Examples1

  1. Example 1

    Input
    5 3
    17 18 17 30 35
    
    Expected output
    35