//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e6 + 10;
int n, k, a[N];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	int alone, group, ans, p1, p2;
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = 0, p2 = 2 * group - 1;
	while (p1 < p2)
		ans = max(ans, a[p1++] + a[p2--]);
	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//06/03/2020
//1398/12/16
//In the name of God ^_^

#include<bits/stdc++.h>
using namespace std;

long long n, k, a, mx;
long long sum;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		mx = max(mx, a);
	}
}

void solve() {
	long long L = 0, R = 2e6;
	while (R - L > 1) {
		long long mid = (L + R) / 2;
		(k * mid  < sum || mid < mx? L = mid: R = mid);
	}
	cout << R;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//06/03/2020
//1398/12/16
//In the name of God ^_^

#include<bits/stdc++.h>
using namespace std;

int sum, n, k, a, mx;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++) {
		cin >> a;
		sum += a;
		mx = max(mx, a);
	}
}

void solve() {
	int L = 0, R = 2e6;
	while (R - L > 1) {
		int mid = (L + R) / 2;
		(k * mid < sum || mid < mx? L = mid: R = mid);
	}
	cout << R;
}
int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e6 + 10;
int n, k, a[N];
int alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));
	for (int i = group * 2; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e5 + 10;
long long n, k, s[N];
long long alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> s[i];
}

void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (s[p1] + s[p2]));
	for (int i = group * 2; i < n; i++)
		ans = max(ans, s[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e6 + 10;
int n, k, a[N];
int alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	alone = min(2 * k - n, n);
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));
	for (int i = group * 2; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e5 + 10;
int n, k, a[N];
int alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));
	for (int i = group * 2; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e5 + 10;
int n, k, a[N];
int alone, group, ans, p1, p2;

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	alone = 2 * k - n;
	group = (n - alone) / 2;
	cout << group << ' ' << alone<< '\n';
	p1 = -1, p2 = 2 * group ;
	while (++p1 < --p2)
		ans = max(ans, (a[p1] + a[p2]));
	for (int i = group * 2; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


//In the name of God ^-^

#include<bits/stdc++.h>
using namespace std;

int const N = 1e6 + 10;
int n, k, a[N];

void read_input() {
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> a[i];
}

void solve() {
	int alone, group, ans, p1, p2;
	alone = 2 * k - n;
	group = (n - alone) / 2;
	p1 = -1, p2 = 2 * group ;
	while (p1++ < p2--)
		ans = max(ans, a[p1] + a[p2]);
	for (int i = group; i < n; i++)
		ans = max(ans, a[i]);
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	read_input();
	solve();
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    double A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    double range_val =0;
    for(int i=0; i< n - i -1; i++)
    {
        range_val = max(range_val, A[n-i-1]+A[i]);
        //cout<<range_val<<endl;
    }
    if(k<=n/2)
    {
        cout<<(int)range_val;
        return 0;
    }

    int val = ceil(ans/k);
    if( val<A[n-1]) cout<<A[n-1];
    else cout<<val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    int A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    int val = ceil(ans/k);
    //cout<<val;
    if(val<A[n-1]) cout<<A[n-1];
    else cout<<val;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,k,x;
    cin>>n>>k;
    vector<long long int> v,res;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        v.push_back(x);
    }
    reverse(v.begin(),v.end());
    for(int i=0; i<k; i++)
    {
        res.push_back(v[i]);
    }
    for(int i= k, j = k-1; i<n; i++,j--)
    {
        res[j] += v[i];
    }
    sort(res.begin(),res.end());
    cout<<res[res.size()-1];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    int k;
    cin>>n>>k;
    int A[n];
    long long int ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    int range_val =0;
    for(int i=0,j=n-1; i<j; i++,j--)
    {
        range_val = max(range_val, A[j]+A[i]);
        //cout<<range_val<<endl;
    }

    int val = ceil(ans/(1.0*k));
    int r_v = range_val;
    //cout<<val<<" "<<r_v<<endl;
    if(2*k==n)
    {
        cout<<max(val,r_v);
        return 0;
    }
    if( val<A[n-1]) cout<<A[n-1];
    else cout<<val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    int k;
    cin>>n>>k;
    int A[n];
    long long int ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    if(n==2)
    {
        cout<<A[0] + A[1];
        return 0;
    }
    int range_val =0;
    for(int i=0,j=n-1; i<j; i++,j--)
    {
        range_val = max(range_val, A[j]+A[i]);
        //cout<<range_val<<endl;
    }
    //int val = ceil(ans/(1.0*k));
    int r_v = range_val;
    //cout<<val<<" "<<r_v<<endl;
    if(2*k==n)
    {
        cout<<r_v;
        return 0;
    }
    if( A[n-1] > A[n-2] + A[n-3]) cout<<A[n-1];
    else cout<<min(A[n-1] + A[0],A[n-2] + A[n-3]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    int k;
    cin>>n>>k;
    int A[n];
    long long int ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    if(n==2)
    {
        cout<<A[0] + A[1];
        return 0;
    }
    int range_val =0;
    for(int i=0,j=n-1; i<j; i++,j--)
    {
        range_val = max(range_val, A[j]+A[i]);
        //cout<<range_val<<endl;
    }
    //int val = ceil(ans/(1.0*k));
    int r_v = range_val;
    //cout<<val<<" "<<r_v<<endl;
    if(2*k==n)
    {
        cout<<r_v;
        return 0;
    }
    if( A[n-1] > A[n-2] + A[n-3]) cout<<A[n-1];
    else cout<<A[n-2] + A[n-3];

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    double A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    double range_val =0;
    for(int i=0; i< n - i -1; i++)
    {
        range_val = max(range_val, A[n-i-1]+A[i]);
        //cout<<range_val<<endl;
    }
    if(k<=n/2)
    {
        cout<<range_val;
        return 0;
    }

    int val = ceil(ans/k);
    if( val<A[n-1]) cout<<A[n-1];
    else cout<<val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n,k,x;
    cin>>n>>k;
    vector<long long int> v,res;
    for(int i=0; i<n; i++)
    {
        cin>>x;
        v.push_back(x);
    }
    reverse(v.begin(),v.end());
    for(int i=0; i<k; i++)
    {
        res.push_back(v[i]);
    }
    for(int i= k, j = k-1; i<n; i++,k--)
    {
        res[j] += v[i];
    }
    sort(res.begin(),res.end());
    cout<<res[res.size()-1];
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    int k;
    cin>>n>>k;
    int A[n];
    long long int ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    if(n==2 && k==1)
    {
        cout<<A[0] + A[1];
        return 0;
    }
    else if (n==2 && k==2)
    {
        cout<<A[1];
        return 0;
    }
    int range_val =0;
    for(int i=0,j=n-1; i<j; i++,j--)
    {
        range_val = max(range_val, A[j]+A[i]);
        //cout<<range_val<<endl;
    }
    //int val = ceil(ans/(1.0*k));
    int r_v = range_val;
    //cout<<val<<" "<<r_v<<endl;
    if(2*k==n)
    {
        cout<<r_v;
        return 0;
    }
    if( A[n-1] > A[n-2] + A[n-3]) cout<<A[n-1];
    else cout<<min(r_v,A[n-2] + A[n-3]);

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    double A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    double range_val =0;
    for(int i=0; i< n - i -1; i++)
    {
        range_val = max(range_val, A[n-i-1]+A[i]);
        //cout<<range_val<<endl;
    }
    if(k<=n/2)
    {
        cout<<(int)range_val;
        return 0;
    }

    int val = ceil(ans/k);
    if( val<A[n-1]) cout<<(int)A[n-1];
    else cout<<(int)val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    int A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    if(k<=n/2)
    {
        cout<<A[n-1] + A[n-2];
        return 0;
    }

    int val = ceil(ans/k);
    //cout<<val;
    if( val<A[n-1]) cout<<A[n-1];
    else cout<<val;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    int n;
    double k;
    cin>>n>>k;
    double A[n];
    double ans =0;
    for(int i=0; i<n; i++)
    {
        cin>>A[i];
        ans+=A[i];
    }
    double range_val =0;
    for(int i=0,j=n-1; i<j; i++,j--)
    {
        range_val = max(range_val, A[j]+A[i]);
        //cout<<range_val<<endl;
    }

    int val = ceil(ans/k);
    int r_v = range_val;
    //cout<<val<<" "<<r_v<<endl;
    if(k==n/2)
    {
        cout<<max(val,r_v);
        return 0;
    }
    if( val<A[n-1]) cout<<A[n-1];
    else cout<<val;

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main ()
{
    long long int n,k,x;
    cin>>n>>k;
    vector<long long int> v,res;
    for(long long int i=0; i<n; i++)
    {
        cin>>x;
        v.push_back(x);
    }
    reverse(v.begin(),v.end());
    for(int i=0; i<min(k,n); i++)
    {
        res.push_back(v[i]);
    }
    for(int i= k, j = k-1; i<n; i++,j--)
    {
        res[j] += v[i];
    }
    sort(res.begin(),res.end());
    cout<<res[res.size()-1];
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define INF 1<<30
using namespace std;

typedef long long ll;
typedef vector<int> vi;

vi cowbells;
int n, k;

bool can(int target) {
	int curr = 0, total = 0, count = 0;
	for (int i = 0; i < cowbells.size(); i++) {
		if (curr + cowbells[i] <= target && count < 2) {
			curr += cowbells[i];
			count++;
		}
		else {
			total++;
			if (total > k) return 0;
			curr = cowbells[i];
			count = 1;
			if (curr > target) return 0;
		}
	}
	total++;
	if (total > k) return 0;
	return 1;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	cowbells.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> cowbells[i];
	}

	int low = 0, high = 3000000, mid;
	while (low < high) {
		mid = low + (high-low)/2;
		if (can(mid)) high = mid;
		else low = mid + 1;
	}
	if (can(low-1)) cout << low-1 << endl;
	else if (can(low)) cout << low << endl;
	else if (can(low+1)) cout << low+1 << endl;
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define INF 1<<30
using namespace std;

typedef long long ll;
typedef vector<int> vi;

vi cowbells;
int n, k;

bool can(int target) {
	int curr = 0, total = 0, count = 0;
	for (int i = 0; i < cowbells.size(); i++) {
		if (curr + cowbells[i] <= target && count < 2) {
			curr += cowbells[i];
			count++;
		}
		else {
			total++;
			if (total > k) return 0;
			curr = cowbells[i];
			count = 1;
			if (curr > target) return 0;
		}
	}
	return 1;
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	cowbells.resize(n);
	for (int i = 0; i < n; i++) {
		cin >> cowbells[i];
	}

	int low = 0, high = 3000000, mid;
	while (low < high) {
		mid = low + (high-low)/2;
		if (can(mid)) high = mid;
		else low = mid + 1;
	}
	if (can(low+1)) cout << low+1 << endl;
	else if (can(low)) cout << low << endl;
	else if (can(low-1)) cout << low-1 << endl;
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define INF 1<<30
using namespace std;

typedef long long ll;
typedef vector<int> vi;

vi cowbells;
int n, k;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	cowbells.resize(n);
	int highest = -1;
	for (int i = 0; i < n; i++) {
		cin >> cowbells[i];
		highest = max(highest, cowbells[i]);
	}
	if (k >= n) {
		cout << highest << endl;
		return 0;
	}
	int i = 0, j = n - (2*k - n) - 1;
	// cout << i << " " << j << endl;
	int ans = highest;
	while (i < j) {
		ans = max(ans, cowbells[j]+cowbells[i]);
		i++; j--;
	}
	cout << ans << endl;
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

typedef long long ll;
typedef vector<ll> vi;

class BIT
{
private:
	ll* tree;
	int size;
public:
	BIT(int n) : size(n) {
		tree = new ll[n];
		std::fill(tree, tree+n, 0);
	}
	~BIT() {
		delete[] tree;
	};
	ll query(int idx);
	void update(int idx, int val);
};

ll BIT::query(int idx) {
	ll sum = 0;
	while (idx > 0) {
		sum += tree[idx];
		idx -= (idx&-idx);
	}
	return sum;
}

void BIT::update(int idx, int val) {
	while (idx < size) {
		tree[idx] += val;
		idx += (idx&-idx);
	}
}

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	vi a, b;
	set<ll> todos;
	map<ll, int> rank;
	int n, m, x;
	cin >> n >> m;
	a = vi(n); b = vi(m);
	for (int i = 0; i < n; i++) {
		cin >> x;
		a[i] = x;
		todos.insert(x);
	}
	for (int j = 0; j < m; j++) {
		cin >> x;
		b[j] = x;
		todos.insert(x);
	}

	int curr = 1;
	for (auto it : todos) {
		if (!rank.count(it)) rank[it] = curr++;
	}

	BIT tree(curr+100);
	for (int i = 0; i < n; i++) {
		int x = rank[a[i]];
		tree.update(x, 1);
	}

	for (int i = 0; i < m; i++) {
		if (i) cout << " ";
		int x = rank[b[i]];
		cout << tree.query(x);
	}
	cout << endl;
	return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define INF 1<<30
using namespace std;

typedef long long ll;
typedef vector<int> vi;

vi cowbells;
int n, k;

bool can(int target) {
    int curr, total = 0;
    for (int i = 0; i < cowbells.size(); i++) {
        if (curr + cowbells[i] <= target) {
            curr += cowbells[i];
        }
        else {
            total++;
            if (total > k) return 0;
            curr = cowbells[i];
            if (curr > target) return 0;
        }
    }
    return 1;
}

int main () {
    ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

    cin >> n >> k;
    cowbells.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> cowbells[i];
    }

    int low = 0, high = 3000000, mid;
    while (low < high) {
        mid = low + (high-low)/2;
        if (can(mid)) high = mid;
        else low = mid + 1;
    }
    cout << low << endl;
    return 0;
}


#include <bits/stdc++.h>
#define endl '\n'
#define fst first
#define snd second
#define INF 1<<30
using namespace std;

typedef long long ll;
typedef vector<int> vi;

vi cowbells;
int n, k;

int main () {
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	cin >> n >> k;
	cowbells.resize(n);
	int highest = -1;
	for (int i = 0; i < n; i++) {
		cin >> cowbells[i];
		highest = max(highest, cowbells[i]);
	}
	if (k >= n) {
		cout << highest << endl;
		return 0;
	}
	int i = 0, j = n - (2*k - n) - 1;
	// cout << i << " " << j << endl;
	int ans = highest;
	while (i < j) {
		ans = max(ans, cowbells[j]-cowbells[i]);
		i++; j--;
	}
	cout << ans << endl;
	return 0;
}


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                long long maxi=0;
                if(x/2==k)
                {
                    int j=0;
                   for(int i=x-1;i>=x/2;i--)
                   {
                       sum=a[i]+a[j];
                       j++;
                       if(sum>maxi)
                        maxi=sum;
                   }
                    cout<<maxi;
                }

                else
                {
                     r=a[x-1];
                     int j=0;
               for(int i=x-k;i>=(x-k)/2;i--)
                   {
                       sum=a[i]+a[j];
                       j++;
                       if(sum>maxi)
                        maxi=sum;
                   }
                   if(r>maxi)
                    cout<<r;
                    else
                        cout<<maxi;
                }

            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                if(x==k/2)
                {
                    sum=a[x-1]+a[0];
                    a[x-k]+a[x-k-1];
                    if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                    return 0;
                }

                else
                {
                     r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                }

            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                if(x/2==k)
                {
                    sum=a[x-1]+a[0];
                    a[x-k]+a[x-k-1];
                    if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                    return 0;
                }

                else
                {
                     r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                }

            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                if(x%k==1)
                {
                    r=a[x-1];
                    sum=a[x-k]+a[x-k-1];
                }

                else
                {
                      sum=a[x-1]+a[0];
                }

                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r,sum=0;
          cin>>x>>k;
            int a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k==x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                long long maxi=0;
                if(x/2==k)
                {
                    int j=0;
                   for(int i=x-1;i>=x/2;i--)
                   {
                       sum=a[i]+a[j];
                       j++;
                       if(sum>maxi)
                        maxi=sum;
                   }
                    cout<<maxi;
                }

                else
                {
                     r=a[x-1];
                     int j=(x-k)*2-1;
               for(int i=0;i<=(x-k);i++)
                   {
                       sum=a[i]+a[j];
                       j--;
                       if(sum>maxi)
                        maxi=sum;
                   }
                   if(r>maxi)
                    cout<<r;
                    else
                        cout<<maxi;
                }

            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                if(x/k==1)
                {
                    r=a[x-1];
                    sum=a[x-k]+a[x-k-1];
                }

                else
                {
                      sum=a[x-1]+a[0];
                }

                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r,sum=0;
          cin>>x>>k;
            int a[100000];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k==x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                r=a[x-1];
                for(int i=x-k;i>=0;i--)
                sum+=a[i];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r=0,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                if(x/2==k)
                {
                    sum=a[x-1]+a[0];
                    r=a[x-k]+a[x-k-1];
                    if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                    return 0;
                }

                else
                {
                     r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
                }

            }
        return 0;
        }


    #include<iostream>
    #include<string>
    #include<algorithm>
    #include<utility>
    #include<iomanip>
    #include<stdio.h>
    #include<cmath>
    #include<map>
    #include<vector>
    #include<numeric>
    using namespace std;
    int main()
    {
          long long x,k,r,sum=0;
          cin>>x>>k;
            long long a[x];
            for(int i=0;i<x;i++)
            {
                cin>>a[i];
            }
            if(k>=x)
            {
                cout<<a[x-1];
                return 0;
            }

            else
            {
                r=a[x-1];
                sum=a[x-k]+a[x-k-1];
                if(sum>=r)
                    cout<<sum;
                else
                    cout<<r;
            }
        return 0;
        }


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns && ns > 0 && ks > 0) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    if (ns > 0 && ks == 0)
        return false;
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
    }
    return true;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns && ns > 0 && ks > 0) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    if (ns > 0 && ks == 0)
        return false;
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
        else
            ns--;
    }
    return ns < 1;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int a[N];
void solve() {
    int ans = a[n - 1];
    while (k * 2 > n) {
        n--;
        k--;
    }
    for (int i = 0; i < k; i++) {
        ans = max(ans, a[i] + a[k * 2 - i - 1]);
    }
    printf("%d", ans);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns) {
        ns--;
        ks--;
    }
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1]);
            return false;
    }
    return true;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    sort(s, s + n);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
    }
    return true;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns && ns > 0 && ks > 0) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
    }
    return true;
}
void solve() {
    int l = -1;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int prev = p;
    int ps = 0;
    int u = 1;
    for (int i = 0; i < n; i++) {
        if (prev >= s[i] && ps < 2) {
            prev -= s[i];
            ps++;
        }
        else {
            u++;
            prev = p;
            if (s[i] > prev)
                return false;
            prev -= s[i];
            ps = 1;
        }
    }
    return u <= k;
}
void solve() {
    int l = 0;
    int r = s[n - 1]*2+1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    sort(s, s + n);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int prev = p;
    int ps = 0;
    int u = 1;
    for (int i = 0; i < n; i++) {
        if (prev >= s[i] && ps < 2) {
            prev -= s[i];
            ps++;
        }
        else {
            u++;
            prev = p;
            if (s[i] > prev)
                return false;
            prev -= s[i];
            ps = 1;
        }
    }
    return u <= k;
}
void solve() {
    int l = -1;
    int r = s[n - 1] * 2;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
    sort(s, s + n);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns) {
        ns--;
        ks--;
    }
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
    }
    return true;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns && ns > 0 && ks > 0) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    if (ns > 0 && ks == 0)
        return false;
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
        else
            ns-=2;
    }
    return ns < 1;
}
void solve() {
    int l = 0;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <sstream>
#include <cstring>
#include <cassert>
using namespace std;

const int N = 2e5;

int n, k;
int s[N];
bool check(int p) {
    int ks = k;
    int ns = n;
    while (ks * 2 > ns && ns > 0 && ks > 0) {
        if (s[ns] > p)
            return false;
        ns--;
        ks--;
    }
    if (ns > 0 && ks == 0)
        return false;
    for (int i = 0; i < ks; i++) {
        if (p < s[i] + s[ks * 2 - i - 1])
            return false;
    }
    return true;
}
void solve() {
    int l = -1;
    int r = s[n - 1] * 2 + 1;
    while (r - l > 1) {
        int mid = (r + l) / 2;
        if (check(mid)) {
            r = mid;
        }
        else {
            l = mid;
        }
    }
    printf("%d", r);
}

void read() {
    scanf("%d %d", &n, &k);
    for (int i = 0; i < n; i++) scanf("%d", &s[i]);
}

int main() {
    read();
    solve();
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define eps 1e-16
#define pai 3.141592653589793
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn=100005;
LL mm(int n,int m)
{
    LL s=1;
    LL k=n;
    while(m)
    {
        if(m&1)
        {
            s=s*k;
            s%=mod;
        }
        k=k*k;
        k%=mod;
    }
    return s;
}
int a[maxn];
int main()
{
    int i,j,n,m;
    int le,ri,mid;
    le=1;
    ri=10000000;
    cin>>n>>m;
    for(i=1; i<=n; i++)
    {
        scanf("%d",&a[i]);
    }
    while(le<=ri)
    {
        mid=(le+ri)/2;
        int x,y;
        x=1;
        y=n;
        int p=0;
        while(x<y)
        {
            if(a[x]+a[y]<=mid)
            {
                x++;
                y--;
                p++;
            }
            else
            {
                if(a[y]<=mid)
                {
                    y--;
                    p++;
                }
                else
                {
                    break;
                }
            }
        }

        if(x>y)
        {
            if(p<=m)
                ri=mid-1;
            else
                le=mid+1;
        }
        else le=mid+1;
    }
    printf("%d\n",le);
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define eps 1e-16
#define pai 3.141592653589793
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn=100005;
LL mm(int n,int m)
{
    LL s=1;
    LL k=n;
    while(m)
    {
        if(m&1)
        {
            s=s*k;
            s%=mod;
        }
        k=k*k;
        k%=mod;
    }
    return s;
}
int a[maxn];
int main()
{
    int i,j,n,m;
    int le,ri,mid,mx;
    cin>>n>>m;

    scanf("%d",&a[1]);
    mx=a[1];

    for(i=2; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
    }

    le=mx;
    ri=mx*2;

    while(le<=ri)
    {
        mid=(le+ri)/2;
        int x,y;
        x=1;
        y=n;
        int p=0;
        while(x<=y)
        {
            if(x<y && a[x]+a[y]<=mid)
            {
                x++;
                y--;
                p++;
            }
            else
            {
                if(a[y]<=mid)
                {
                    y--;
                    p++;
                }
                else
                {
                    break;
                }
            }
        }

        if(x>=y)
        {
            if(p<=m)
                ri=mid-1;
            else
                le=mid+1;
        }
        else le=mid+1;
    }

    printf("%d\n",le);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define eps 1e-16
#define pai 3.141592653589793
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn=100005;
LL mm(int n,int m)
{
    LL s=1;
    LL k=n;
    while(m)
    {
        if(m&1)
        {
            s=s*k;
            s%=mod;
        }
        k=k*k;
        k%=mod;
    }
    return s;
}
int a[maxn];
int main()
{
    int i,j,n,m;
    int le,ri,mid,mx;
    cin>>n>>m;

    scanf("%d",&a[1]);
    mx=a[1];

    for(i=2; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
    }

    le=mx;
    ri=mx*2;

    while(le<ri)
    {
        mid=(le+ri)/2;
        int x,y;
        x=1;
        y=n;
        int p=0;
        while(x<=y)
        {
            if(x<y && a[x]+a[y]<=mid)
            {
                x++;
                y--;
                p++;
            }
            else
            {
                if(a[y]<=mid)
                {
                    y--;
                    p++;
                }
                else
                {
                    break;
                }
            }
        }

        if(x>=y)
        {
            if(p==m)
                ri=mid;
            else if(p<m)
                ri=mid-1;
            else
                le=mid+1;
        }
        else le=mid+1;
    }

    printf("%d\n",le);
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll x,n,k,fi=1,la,mx=0,mid,sum=0,i;
    cin>>n>>k;

    fr(i,1,n)
    {
        scanf("%I64d",&x), sum+=x ;
        mx=max(mx,x);
    }

    la=(ll)mx*2;

    while(fi<la)
    {
        mid=(fi+la)/2;

        if(k*mid>=sum)
        {
            if(mid<mx)
                fi=mid+1;
            else
                la=mid;
        }
        else
            fi=mid+1;

        // if(fi==la)
        //   break;
    }

    cout<<fi<<endl;

    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define eps 1e-16
#define pai 3.141592653589793
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn=100005;
LL mm(int n,int m)
{
    LL s=1;
    LL k=n;
    while(m)
    {
        if(m&1)
        {
            s=s*k;
            s%=mod;
        }
        k=k*k;
        k%=mod;
    }
    return s;
}
int a[maxn];
int main()
{
    int i,j,n,m;
    int le,ri,mid,mx;
    cin>>n>>m;

    scanf("%d",&a[1]);
    mx=a[1];

    for(i=2; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
    }

    le=mx;
    ri=mx*2;

    while(le<ri)
    {
        mid=(le+ri)/2;
        int x,y;
        x=1;
        y=n;
        int p=0;
        while(x<=y)
        {
            if(x<y && a[x]+a[y]<=mid)
            {
                x++;
                y--;
                p++;
            }
            else
            {
                if(a[y]<=mid)
                {
                    y--;
                    p++;
                }
                else
                {
                    break;
                }
            }
        }

        if(x>y)
        {
            if(p==m)
                ri=mid;
            else if(p<m)
                ri=mid-1;
            else
                le=mid+1;
        }
        else le=mid+1;
    }

    printf("%d\n",le);
    return 0;
}


#include<cstdio>
#include<cstring>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#include<algorithm>
#define eps 1e-16
#define pai 3.141592653589793
using namespace std;
typedef long long LL;
const int mod=1000000007;
const int maxn=100005;
LL mm(int n,int m)
{
    LL s=1;
    LL k=n;
    while(m)
    {
        if(m&1)
        {
            s=s*k;
            s%=mod;
        }
        k=k*k;
        k%=mod;
    }
    return s;
}
int a[maxn];
int main()
{
    int i,j,n,m;
    int le,ri,mid,mx;
    cin>>n>>m;

    scanf("%d",&a[1]);
    mx=a[1];

    for(i=2; i<=n; i++)
    {
        scanf("%d",&a[i]);
        mx=max(mx,a[i]);
    }

    le=mx;
    ri=mx*2;

    while(le<=ri)
    {
        mid=(le+ri)/2;
        int x,y;
        x=1;
        y=n;
        int p=0;
        while(x<y)
        {
            if(a[x]+a[y]<=mid)
            {
                x++;
                y--;
                p++;
            }
            else
            {
                if(a[y]<=mid)
                {
                    y--;
                    p++;
                }
                else
                {
                    break;
                }
            }
        }

        if(x>=y)
        {
            if(p<=m)
                ri=mid-1;
            else
                le=mid+1;
        }
        else le=mid+1;
    }
    printf("%d\n",le);
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll x,n,k,fi=1,la,mx=0,mid,sum=0,i,a,b;

    cin>>n>>k;

    fr(i,1,n)
    {
        scanf("%I64d",&x), sum+=x ;
        mx=max(mx,x);

        if(i==1)
            a=x;
        else if(i==n)
            b=x;
    }

    la=(ll)mx*2;

    //cout<<sum<<endl;

    while(fi<la)
    {
        //   cout<<fi<<" "<<la<<endl;

        mid=(fi+la)/2;

        if(k*mid>=sum)
        {
            if(mid<(a+b))
                fi=mid+1;
            else
                la=mid;
        }
        else
            fi=mid+1;

  //  cout<<fi<<" "<<la<<endl;
        // if(fi==la)
        //   break;
    }

    cout<<fi<<endl;

    return 0;
}


#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define ull unsigned long long
#define pb push_back

#define fr(i,a,b)   for(i=a;i<=b;i++)
#define frn(i,a,b)  for(i=a;i>=b;i--)
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ll x,n,k,fi,la,mx=0,mid,sum=0,i,a,b;

    cin>>n>>k;

    fr(i,1,n)
    {
        scanf("%I64d",&x), sum+=x ;
        mx=max(mx,x);
    }

    fi=mx;
    la=(ll)mx*2;

    //cout<<sum<<endl;

    while(fi<la)
    {
        //   cout<<fi<<" "<<la<<endl;
        mid=(fi+la)/2;

        if(k*mid>=sum)
        {
            la=mid;
        }
        else
            fi=mid+1;

  //  cout<<fi<<" "<<la<<endl;
        // if(fi==la)
        //   break;
    }

    cout<<fi<<endl;

    return 0;
}


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    if(n%2==1)
    {
        n--;
        m--;
    }

    cnt=m;
    b =n-1;
    for(i=n-1;i>=0;i--)
    {
        a = i/2+i%2;
        if(a<=(cnt-1)) cnt--;
        else break;
        b = i;
    }
    n=b+1;

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

3 2
3 5 7
*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    cnt=m;
    b =n-1;
    for(i=n-1;i>=0;i--)
    {
        a = i/2+i%2;
        if(a<=(cnt-1)) cnt--;
        else break;
        b = i;
    }
    n=b+1;

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    a = n / 2 + n % 2;
    a = m - a;
    n = n - a;
    if(n % 2 && n >= 0) ans = max(ans, inp[n - 1]), n--;

    if(n<=0)
    {
        cout<<ans<<endl;
        return 0;
    }

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    if(n%2==1)
    {
        n--;
        m--;
    }

    cnt=m;
    b =n;
    for(i=n-1;i>=0;i--)
    {
        c = i+1;
        a = c/2+c%2;
//        cout<<cnt<<" "<<a<<endl;
        if(cnt-a>=1)
        {
            cnt--;
            b = i;
        }
        else break;
    }
//    cout<<b<<endl;
    n=b;

    if(n%2==1)
    {
        n--;
        m--;
    }

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

3 2
3 5 7
*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    if(n%2==1)
    {
        n--;
        m--;
    }

    cnt=m;
    b =n;
    for(i=n-1;i>=0;i--)
    {
        c = i+1;
        a = c/2+c%2;
//        cout<<cnt<<" "<<a<<endl;
        if(cnt-a>=1)
        {
            cnt--;
            b = i;
        }
        else break;
    }
//    cout<<b<<endl;
    n=b;

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

3 2
3 5 7
*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 100007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    a = n / 2 + n % 2;
    a = m - a;
    n = n - a;
    if(n % 2 && n >= 0) ans = max(ans, inp[n - 1]), n--;
    for(i = 0, j = n - 1; i<n, j >= 0; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 200007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k, n;
    ll low, hi, md, inp[MX], sm, ff;
    sc2(n, m);
    for(i = 0; i < n; i++) sc(inp[i]);
    ans = inp[n - 1];
    cnt=m;
    for(i=n-1;i>=0;i--)
    {
        a = i/2+i%2;
        if(a<=(cnt-1)) cnt--;
        else break;
        b = i;
    }
    n=b+1;

    for(i = 0, j = n - 1; i<j ; i++, j--) ans = max(ans, inp[i] + inp[j]);
    cout << ans << endl;
    return 0;
}

/*

*/


#include<algorithm>
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
#include<deque>
#include<climits>
#include<complex>

using namespace std;
//-------------------------------------

#define ll long long
#define sc(x) scanf("%lld",&x)
#define sc2(x,y) scanf("%lld%lld",&x,&y)
#define sci(x) scanf("%d",&x)
#define sci2(x,y) scanf("%d%d",&x,&y)

#define mem(x) memset(x,0,sizeof x)
#define all(x) x.begin(),x.end()
#define pb(x)  push_back(x);
#define xx first
#define yy second
#define inf 999999999999999
#define mkp(x,y) make_pair(x,y)
#define pii pair<ll,ll>

//---------------------------------------

#define MX 100007
#define pi 2*acos(0.00)

#define open       freopen("input.txt","r",stdin)
#define close      freopen ("output.txt","w",stdout)

int main()
{
    ll i, j, l, u, v, w, x, y, z, a, b, c, d, e, f, t = 1, tc;
    ll flg, sz, cnt, gt, ans, mx, mn;
    ll m, k,n;
    ll low,hi,md,inp[MX],sm,ff;
    sc2(n,m);
    for(i=0;i<n;i++) sc(inp[i]);
    low = 1,hi=100000000020ll;
    ans = inf;
    while(low<=hi)
    {
        md = (low+hi)/2;
        cnt = 1;
        sm = 0;
        ff = 0;
        for(i=0;i<n;i++)
        {
            if(inp[i]>md) cnt = inf;
            if(sm+inp[i]>md || ff==2) sm  = inp[i],cnt++,ff=1;
            else sm+=inp[i],ff++;
        }
//        cout<<md<<" "<<cnt<<endl;
        if(cnt>m)
        {
            low = md+1;
        }
        else
        {
            ans = min(ans,md);
            hi= md-1;
        }
    }
    cout<<ans<<endl;

    return 0;
}

/*

*/


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0, x = n / k;
	multiset < int > M;
	for(int i = 1; i <= n; ++i)
		M.insert(a[i]);
	while (sz(M) > k) {
		int x = *(M.begin());
		M.erase(M.find(x));
		auto it = *M.begin();
		M.erase(M.begin());
		it += x;
		res = max(res, it);
	}
	for(auto to : M)
		res = max(res, to);
	cout << res;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) int(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0, x = n / k;
	for(int i = 1; i <= n;) {
		curs = a[i];
		if(x)
			x--,curs += a[i + 1], i += 2;
		else
			i++;
		res = max(res, curs);
	}
	cout << res;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) int(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int xd = n % k, len = n / k;

	int res = 0;

	int curs = 0;
	for(int i = 1; i <= len + xd; ++i) {
		curs += a[i];
	}
	res = curs;
	for(int i = len + xd + 1; i <= n;) {
		curs = 0;
		int cnt = len;
		while(cnt--) {
			curs += a[i];
			i++;
		}
		res = max(res, curs);
	}
	cout << res;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) int(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0, x = n / k - (n == k);
	for(int i = 1; i <= n;) {
		curs = a[i];
		if(x)
			x--,curs += a[i + 1], i += 2;
		else
			i++;
		res = max(res, curs);
	}
	cout << res;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0;
	multiset < int > M;
	for(int i = 1; i <= n; ++i)
		M.insert(a[i]);
	while (sz(M) > k) {
		int x = *(M.begin());
		M.erase(M.find(x));
		auto it = *M.begin();
		M.erase(M.begin());
		it += x;
		if(it < (int)1e15)
		res = max(res, it);
		M.insert((int)1e15);
	}
	for(auto to : M)
		if(to != (int)1e15)
			res = max(res, to);
	cout << res;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0;
	multiset < int > M;
	reverse(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i) {
		if(sz(M) == k) {
			int x = *M.begin();
			M.erase(M.begin()); res = max(res, x + a[i]);
			M.insert((int)1e9);
		}
		else
			M.insert(a[i]); res = max(res, a[i]);
	}
	cout << res;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) int(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0, x = n - k;
	for(int i = 1; i <= n;) {
		curs = a[i];
		if(x > 0)
			x--,curs += a[i + 1], i += 2;
		else
			i++;
		res = max(res, curs);
	}
	cout << res;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) int(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN];

int main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int xd = n % k, len = n / k;

	int res = 0;

	int curs = 0;
	for(int i = 1; i <= len + xd; ++i) {
		curs += a[i];
	}
	res = curs;
	for(int i = len + xd + 1; i <= n;) {
		curs = 0;
		int cnt = len;
		while(cnt--) {
			curs += a[i];
			i++;
		}
		res = max(res, curs);
	}
	cout << res;

	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0;
	multiset < int > M;
	reverse(a + 1, a + 1 + n);
	for(int i = 1; i <= n; ++i) {
		if(sz(M) == k) {
			int x = *M.begin();
			M.erase(M.begin());
			M.insert(x + a[i]);
		}
		else
			M.insert(a[i]);
	}
	cout << *(--M.end());
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0;
	multiset < int > M;
	for(int i = 1; i <= n; ++i)
		M.insert(a[i]);
	while (sz(M) > k) {
		cerr << sz(M) << ' '<< k << endl;
		int x = *(M.begin());
		M.erase(M.find(x));
		auto it = *M.begin();
		M.erase(M.begin());
		it += x;
		res = max(res, it);
		k--;
	}
	for(auto to : M)
		res = max(res, to);
	cout << res;
	return 0;
}


#include <bits/stdc++.h>

#define pb push_back
#define mp make_pair
#define ll long long
#define sz(s) (int)(s.size())
#define ull unsigned long long
#define all(s) s.begin(),s.end()
#define int long long

using namespace std;

const int MAXN = 2e5 + 256;
const char nxt = '\n';
inline bool Pal (const string& s) {
	return equal(s.begin(), s.end(), s.rbegin());
}
int n, k, a[MAXN], bl[MAXN];

main () {
	ios_base::sync_with_stdio(0);cin.tie(0);
	#ifdef accepted
		freopen (".in", "r", stdin);
		freopen (".out", "w", stdout);
	#endif
	cin >> n >> k;

	for(int i = 1; i <= n; ++i)
		cin >> a[i];

	int res = 0;
	int curs = 0;
	multiset < int > M;
	for(int i = 1; i <= n; ++i)
		M.insert(a[i]);
	while (sz(M) > k) {
		int x = *(M.begin());
		M.erase(M.find(x));
		auto it = *M.begin();
		M.erase(M.begin());
		it += x;
		res = max(res, it);
		M.insert((int)1e15);
	}
	for(auto to : M)
		if(to != (int)1e15)
		res = max(res, to);
	cout << res;
	return 0;
}


#include<bits/stdc++.h>
using namespace std;

int main()
{
	int n,k,ans;
	int s[100007];
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
	}
	ans=s[n];
	if(n>k)
	{
		for(int i=1;i<=2*(n-k);i++)
        {
            ans=max(ans,s[i]+s[2*(n-k)-i+1]);
        }
	}
	printf("%d",ans);
	return 0;
 }


#include <cstring>
#include <iostream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cstdio>

#define ll long long
#define sc scanf
#define pr printf
#define D "%d"
#define D2 "%d%d"
#define D3 "%d%d%d"
#define F %llf

#define ll long long
#define sc scanf
#define pr printf
#define D "%d"
#define D2 "%d%d"
#define D3 "%d%d%d"
#define F %llf
#define I %I64d

#define fin for(int i=1;i<=n;i++)
#define fim for(int j=1;j<i;j++)
#define fri freopen("1text.in.txt","r",stdin);
#define fro freopen("text.txt","w",stdout);
#define seto struct o{int x;int y;};bool comp(o a,o b){return a.x>b.x;}
#define prio priority_queue<int>q;
#define prio1 priority_queue<int,vector<int>,greater<int> >q;
#define pb push_back
#define MAP map<int,int>mp;map<int,int>::iterator it;
#define mapgo for(it=mp.begin();it!=mp.end();it++)
#define vec vector<int>
using namespace std;
ll n,k;
ll a[100005];
ll l,r,mid,ans;
bool ck(ll x)
{
	ll tot=0;
	for(int i=1,j=n;i<=j;)
	{
		if(a[i]+a[j]<=x)
		{
			i++;
			j--;
			tot++;
		}else
		if(a[i]<=x)
		{
			i++;
			tot++;
		}
		else
		return 0;

	}
	//cout<<mid<<" "<<tot<<endl;
	if(tot<=k)return 1;

	return 0;
}
int main()
{
sc("%I64d%I64d",&n,&k);
for(int i=n;i>=1;i--)
{
	sc("%I64d",&a[i]);
}
l=1;r=1000000000;
while(l<=r)
{
	mid=(l+r)/2;
	if(ck(mid))
	{
		ans=mid;
		r=mid-1;
	}
	else
	{
		l=mid+1;
	}
}
printf("%I64d",ans);
	return 0;
}
/*

*/


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26],rf[26],rl[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        fill(re,re+26,0);
        fill(rf,rf+26,-1);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            if(rf[s[i]-'a']==-1) rf[s[i]-'a']=i;
            rl[s[i]-'a']=i;
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int dp[t.length()];
            dp[0]=1;
            for(int i=1;i<t.length();i++){
                if(rl[t[i]-'a']<=rf[t[i-1]-'a']){
                    dp[i]=dp[i-1]+1;
                }else{
                    dp[i]=dp[i-1];
                }
            }
            printf("%d\n",dp[t.length()-1]);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        fill(re,re+26,0);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=0;
            int ss=0,ts=0;
            while(ts<t.length()){
                ss=0;
                ans++;
                while(ss<s.length() && ts<t.length()){
                    if(s[ss]==t[ts]){
                        ss++;
                        ts++;
                    }else ss++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26];
vector<int> pos[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<26;i++) pos[i].clear();
        fill(re,re+26,0);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            pos[s[i]-'a'].push_back(i);
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=1,ss=-1,cnt[26]={0};
            for(int i=0;i<t.length();i++){
                int p=t[i]-'a';
                if(ss>=pos[p].back() || cnt[p]>=re[p]){
                    ans++;
                    ss=pos[p][0];
                    fill(cnt,cnt+26,0);
                }else{
                    ss=pos[p][cnt[p]];
                    cnt[p]++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26];
vector<int> pos[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<26;i++) pos[i].clear();
        fill(re,re+26,0);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            pos[s[i]-'a'].push_back(i);
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=1,ss=-1,cnt[26]={0};
            for(int i=0;i<t.length();i++){
                int p=t[i]-'a';
                if(ss>=pos[p].back() || cnt[p]>=re[p]){
                    ans++;
                    ss=-1;
                    i--;
                    fill(cnt,cnt+26,0);
                }else{
                    ss=pos[p][cnt[p]];
                    cnt[p]++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26],rf[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        fill(re,re+26,0);
        fill(rf,rf+26,-1);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            if(rf[s[i]-'a']==-1) rf[s[i]-'a']=i;
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=0;
            int ss=0,ts=0;
            while(ts<t.length()){
                ss=rf[t[ts]-'a'];
                ans++;
                while(ss<s.length() && ts<t.length()){
                    if(s[ss]==t[ts]){
                        ss++;
                        ts++;
                    }else ss++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26];
vector<int> pos[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<26;i++) pos[i].clear();
        fill(re,re+26,0);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            pos[s[i]-'a'].push_back(i);
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=1,ss=-1,cnt[26]={0};
            fill(cnt,cnt+26,-1);
            for(int i=0;i<t.length();i++){
                int p=t[i]-'a';
                if(ss>=pos[p].back() || cnt[p]>=re[p]-1){
                    ans++;
                    ss=-1;
                    i--;
                    fill(cnt,cnt+26,-1);
                }else{
                    ss=pos[p][++cnt[p]];
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
inline int lowbit(int x){return x&(-x);}
int re[26];
vector<int> pos[26];
int main(){
    int t;
    cin>>t;
    while(t--){
        for(int i=0;i<26;i++) pos[i].clear();
        fill(re,re+26,0);
        string s,t;
        cin>>s;
        cin>>t;
        for(int i=0;i<s.length();i++){
            re[s[i]-'a']++;
            pos[s[i]-'a'].push_back(i);
        }
        bool imp=false;
        for(int i=0;i<t.length();i++){
            if(re[t[i]-'a']==0){
                imp=true;
                break;
            }
        }
        if(imp) printf("-1\n");
        else{
            int ans=1,ss=-1,cnt[26]={0};
            fill(cnt,cnt+26,0);
            for(int i=0;i<t.length();i++){
                int p=t[i]-'a';
                if(ss>=pos[p].back() || cnt[p]>=re[p]){
                    ans++;
                    ss=-1;
                    i--;
                    fill(cnt,cnt+26,0);
                }else{
                    ss=pos[p][cnt[p]];
                    cnt[p]++;
                }
            }
            printf("%d\n",ans);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
char s[300005], t[300005];
bool bj;
int T, ans, pos[300005][30];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p == ls + 1) {
					cout<<-1<<endl;
					bj = 1;
					break;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
bool bj;
int T, ans, pos[100005][50];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p == ls + 1) {
					cout<<-1<<endl;
					bj = 1;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
bool bj;
int T, ans, pos[100005][30];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = 1e8;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p >= ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p >= ls + 1) {
					cout<<-1<<endl;
					bj = 1;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[300005], t[300005];
bool bj;
int T, ans, pos[300005][30];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p == ls + 1) {
					cout<<-1<<endl;
					bj = 1;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
bool bj;
int T, ans, pos[100005][100];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 70; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 70; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p == ls + 1) {
					cout<<-1<<endl;
					bj = 1;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[200005], t[200005];
bool vis[26], bj;
int T, ans, pos[200005][26];
int main() {
	cin>>T;
	while(T--) {
		memset(vis, 0, sizeof(vis));
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 1; i <= ls; i++)
		   vis[s[i] - 'a'] = 1;
		for(int i = 1; i <= lt; i++)
		   if(!vis[t[i] - 'a']) {
		   	cout<<-1<<endl;
		   	bj = 1;
		   }
		if(bj) continue;
		for(int i = 0; i < 26; i++)
		   pos[ls][i] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
bool vis[30], bj;
int T, ans, pos[100005][30];
int main() {
	cin>>T;
	while(T--) {
		memset(vis, 0, sizeof(vis));
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 1; i <= ls; i++)
		   vis[s[i] - 'a'] = 1;
		for(int i = 1; i <= lt; i++)
		   if(!vis[t[i] - 'a']) {
		   	cout<<-1<<endl;
		   	bj = 1;
		   }
		if(bj) continue;
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p == ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
			}
		}
		cout<<ans<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
char s[100005], t[100005];
bool bj;
int T, ans, pos[100005][30];
int main() {
	cin>>T;
	while(T--) {
		bj = 0, ans = 1;
		cin>>(s + 1)>>(t + 1);
		int ls = strlen(s + 1), lt = strlen(t + 1);
		for(int i = 0; i <= ls; i++)
		   for(int j = 0; j < 26; j++)
			   pos[i][j] = ls + 1;
		for(int i = ls - 1; i >= 0; i--)
			for(int j = 0; j < 26; j++) {
				if(s[i + 1] - 'a' == j)
				   pos[i][j] = i + 1;
				else
				   pos[i][j] = pos[i + 1][j];
			}
		int p = 0;
		for(int i = 1; i <= lt; i++) {
			p = pos[p][t[i] - 'a'];
			if(p >= ls + 1) {
				ans++;
				p = pos[0][t[i] - 'a'];
				if(p >= ls + 1) {
					cout<<-1<<endl;
					bj = 1;
				}
			}
		}
		if(bj) continue;
		cout<<ans<<endl;
	}
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = 0;
        int counter = 0;
        for (char c : t) {
            vector<int> cur = lets[c - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = 0;
        int counter = 0;
        for (char c : t) {
            vector<int> cur = lets[c - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = -2;
        int counter = 0;
        rep(i, 0, t.size()) {
            vector<int> cur = lets[t[i] - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind + 1);
            if (tmp >= s.size()) {
                ind = -2;
                counter++;
                tmp -= s.size();
            }
            ind = tmp;

            // bool found = false;
            // rep(j, 0, cur.size()) {
            //     if (cur[j] > ind) {
            //         ind = cur[j];
            //         found = true;
            //         break;
            //     }
            // }
            // if (!found) {
            //     counter++;
            //     i--;
            //     ind = -1;
            // }
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


#pragma GCC optimize("unroll-loops,no-stack-protector")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        string ss = s + s;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, ss.size()) lets[ss[i] - 'a'].push_back(i);

        int ind = -2;
        int counter = 0;
        for (char c : t) {
            vector<int> cur = lets[c - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            int tmp = *lower_bound(cur.begin(), cur.end(), ind);
            if (tmp >= s.size()) {
                counter++;
                tmp -= s.size();
            }
            ind = tmp + 1;

            // bool found = false;
            // rep(j, 0, cur.size()) {
            //     if (cur[j] > ind) {
            //         ind = cur[j];
            //         found = true;
            //         break;
            //     }
            // }
            // if (!found) {
            //     counter++;
            //     i--;
            //     ind = -1;
            // }
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}


/*input
3
aabce
ace
abacaba
aax
ty
yyt

*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

vector<int> id[maxn];

void solve(){
	string s,t;
	cin>>s>>t;
	string ss=s+s;

	REP(i,26) id[i].clear();
	REP(i,SZ(ss)) id[ss[i]-'a'].pb(i);

	int pt=0;
	int ans=0;

	for(char c:t){
		if(SZ(id[c-'a'])==0){
			cout<<"-1\n";
			return;
		}

		int tmp=*lower_bound(ALL(id[c-'a']),pt);
		if(tmp>=SZ(s)){
			ans++;
			tmp-=SZ(s);
		}
		pt=tmp+1;
	}
	cout<<ans+1<<'\n';
}

int main(){
	IOS;
	int T;
	cin>>T;
	while(T--) solve();
	return 0;
}


#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include <fstream>

using namespace std;

#define endl '\n'
#define rep(i, l, r) for(int i = l; i < r; i++)
#define per(i, l, r) for(int i = r - 1; i >= l; i--)

typedef long long ll;

const int MOD = 1000000007;

vector<int> lets[26];

int main() {
    // ifstream cin("../in.in");

    int _; cin >> _;
    while (_--) {
        string s, t; cin >> s >> t;
        rep(i, 0, 26) lets[i].clear();
        rep(i, 0, s.size()) lets[s[i] - 'a'].push_back(i);

        int ind = -2;
        int counter = 0;
        rep(i, 0, t.size()) {
            vector<int> cur = lets[t[i] - 'a'];
            if (cur.size() == 0) {
                counter = -1;
                break;
            }

            auto find = lower_bound(cur.begin(), cur.end(), ind + 1);
            if (find == cur.end()) {
                counter++;
                i--;
                ind = -2;
            }
            else ind = *find;

            // bool found = false;
            // rep(j, 0, cur.size()) {
            //     if (cur[j] > ind) {
            //         ind = cur[j];
            //         found = true;
            //         break;
            //     }
            // }
            // if (!found) {
            //     counter++;
            //     i--;
            //     ind = -1;
            // }
        }
        if (counter < 0) cout << -1 << endl;
        else cout << counter + 1 << endl;
    }

    return 0;
}