#include <bits/stdc++.h>

#define fi(a,b,c) for(int a=b; a<=c; a++)
#define fd(a,b,c) for(int a=b; a>=c; a--)
#define fii(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define reset(a,b) memset(a,b, sizeof a)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef unsigned int ui;

const int N = 1009;
const int oo = (int)(1e9);

multiset <int> setin, setout;

int n, k , a[N];

int main() {
    scanf("%d %d", &n, &k);
    fi(i, 1, n ) scanf("%d", &a[i]), setout.insert(a[i]);
    int ans = -oo;
    fi(i, 1, n) fi(j, i, n) {
        int sum = 0;
        fi(u, i , j) {
            sum+= a[u];
            multiset <int> :: iterator it;
            it = setout.lower_bound(a[u]);
            setout.erase(it);
            setin.insert(a[u]);
        }
        multiset <int> ::iterator it1;
        multiset <int> ::iterator it2;
        int cnt;
        for (it1 = setout.end() , it2 = setin.begin(), cnt = 1; cnt <= k && it1 != setout.begin() && it2 != setin.end(); cnt ++ , it2++) {
            it1 --;
            sum -= *(it2);
            sum += *(it1);
        }
        ans = max(ans, sum);
        fi(u, i, j) {
            multiset <int> ::iterator it;
            it = setin.lower_bound(a[u]);
            setin.erase(it);
            setout.insert(a[u]);
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>

#define fi(a,b,c) for(int a=b; a<=c; a++)
#define fd(a,b,c) for(int a=b; a>=c; a--)
#define fii(a,b,c) for(int a=b; a<c; a++)
#define pb push_back
#define mp make_pair
#define ft first
#define sc second
#define reset(a,b) memset(a,b, sizeof a)

using namespace std;

typedef long long ll;
typedef pair <int, int> pii;
typedef unsigned int ui;

const int N = 1009;
const int oo = (int)(1e9);

multiset <int> setin, setout;

int n, k , a[N];

int main() {
    scanf("%d %d", &n, &k);
    fi(i, 1, n ) scanf("%d", &a[i]), setout.insert(a[i]);
    int ans = -oo;
    fi(i, 1, n) fi(j, i, n) {
        int sum = 0;
        fi(u, i , j) {
            sum+= a[u];
            multiset <int> :: iterator it;
            it = setout.lower_bound(a[u]);
            setout.erase(it);
            setin.insert(a[u]);
        }
        multiset <int> ::iterator it1;
        multiset <int> ::iterator it2;
        int cnt;
        for (it1 = setout.end() , it2 = setin.begin(), cnt = 1; cnt <= k && it1 != setout.begin() && it2 != setin.end() && *it1 > *it2; cnt ++ , it2++) {
            it1 --;
            sum -= *(it2);
            sum += *(it1);
        }
        for (; cnt<= k && it2 != setin.end(); cnt ++, it2 ++) {
            if (*(it2) < 0 && it2 != setin.begin())
                sum -= *(it2);
        }
        ans = max(ans, sum);
        fi(u, i, j) {
            multiset <int> ::iterator it;
            it = setin.lower_bound(a[u]);
            setin.erase(it);
            setout.insert(a[u]);
        }
    }

    cout << ans;
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int arr[300],n,k;
ll dp[300][3][20][20];
ll go(int idx,int st,int in,int out)
{
    if(idx==n)
    {
        if(in==out&&st)
            return 0;
        else return -999999999;
    }
    ll &ret=dp[idx][st][in][out];
    if(ret!=0)
        return ret;
    ret=-999999999;
    if(st==0)   //target interval not encountered yet
    {
        //start interval from here
        ret=max(ret,go(idx,1,in,out));
        //don't start interval but take this value
        if(out<k)
            ret=max(ret,go(idx+1,0,in,out+1)+arr[idx]);
        //do nothing
        ret=max(ret,go(idx+1,0,in,out));
    }
    else if(st==1)  //we are inside target interval
    {
        //take this value but do not close the interval
        ret=max(ret,go(idx+1,1,in,out)+arr[idx]);
        //take this value and close interval
        ret=max(ret,go(idx+1,2,in,out)+arr[idx]);
        //dont take this value
        if(in<k)
            ret=max(ret,go(idx+1,1,in+1,out));
        //dont take but close the interval
        if(in<k)
            ret=max(ret,go(idx+1,2,in+1,out));
    }
    else    //target interval has already been processed
    {
        //take this value
        if(out<in)
            ret=max(ret,go(idx+1,2,in,out+1)+arr[idx]);
        else if(out==in)return 0;
        else return -99999999;
        //dont take this vale
        ret=max(ret,go(idx+1,2,in,out));
    }
    return ret;
}
int main()
{
    memset(dp,0,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    cout<<go(0,0,0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int arr[300],n,k;
ll dp[300][3][20][20];
ll go(int idx,int st,int in,int out)
{
    if(idx==n)
    {
        if(in==out&&st)
            return 0;
        else return -999999999;
    }
    ll &ret=dp[idx][st][in][out];
    if(ret!=0)
        return ret;
    ret=-999999999;
    if(st==0)   //target interval not encountered yet
    {
        //start interval from here
        ret=max(ret,go(idx,1,in,out));
        //don't start interval but take this value
        if(out<k)
            ret=max(ret,go(idx+1,0,in,out+1)+arr[idx]);
        //do nothing
        ret=max(ret,go(idx+1,0,in,out));
    }
    else if(st==1)  //we are inside target interval
    {
        //take this value but do not close the interval
        ret=max(ret,go(idx+1,1,in,out)+arr[idx]);
        //take this value and close interval
        ret=max(ret,go(idx+1,2,in,out)+arr[idx]);
        //dont take this value
        if(in<k)
            ret=max(ret,go(idx+1,1,in+1,out));
        //dont take but close the interval
        if(in<k)
            ret=max(ret,go(idx+1,2,in+1,out));
    }
    else    //target interval has already been processed
    {
        //take this value
        if(out<k)
            ret=max(ret,go(idx+1,2,in,out+1)+arr[idx]);
        //dont take this vale
        ret=max(ret,go(idx+1,2,in,out));
    }
    return ret;
}
int main()
{
    memset(dp,0,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    cout<<go(0,0,0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int arr[300],n,k;
ll dp[300][3][20][20],v[300][3][20][20];
ll go(int idx,int st,int in,int out)
{
    if(idx==n)
    {
        if(in==out&&st)
            return 0;
        else return -999999999;
    }
    ll &ret=dp[idx][st][in][out];
    if(v[idx][st][in][out])
        return ret;
    ret=-999999999;
    if(st==0)   //target interval not encountered yet
    {
        //start interval from here
        ret=max(ret,go(idx,1,in,out));
        //don't start interval but take this value
        if(out<k)
            ret=max(ret,go(idx+1,0,in,out+1)+arr[idx]);
        //do nothing
        ret=max(ret,go(idx+1,0,in,out));
    }
    else if(st==1)  //we are inside target interval
    {
        //take this value but do not close the interval
        ret=max(ret,go(idx+1,1,in,out)+arr[idx]);
        //take this value and close interval
        ret=max(ret,go(idx+1,2,in,out)+arr[idx]);
        //dont take this value
        if(in<k)
            ret=max(ret,go(idx+1,1,in+1,out));
        //dont take but close the interval
        if(in<k)
            ret=max(ret,go(idx+1,2,in+1,out));
    }
    else    //target interval has already been processed
    {
        //take this value
        if(out<k)
            ret=max(ret,go(idx+1,2,in,out+1)+arr[idx]);
        //dont take this vale
        ret=max(ret,go(idx+1,2,in,out));
    }
    v[idx][st][in][out]=1;
    return ret;
}
int main()
{
    memset(v,0,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    cout<<go(0,0,0,0);
    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define mod 1000000007
using namespace std;
int arr[300],n,k;
ll dp[300][3][20][20];
ll go(int idx,int st,int in,int out)
{
    if(idx==n)
    {
        if(in==out&&st)
            return 0;
        else return -999999999;
    }
    ll &ret=dp[idx][st][in][out];
    if(ret!=0)
        return ret;
    ret=-999999999;
    if(st==0)   //target interval not encountered yet
    {
        //start interval from here
        ret=max(ret,go(idx,1,in,out));
        //don't start interval but take this value
        if(out<k)
            ret=max(ret,go(idx+1,0,in,out+1)+arr[idx]);
        //do nothing
        ret=max(ret,go(idx+1,0,in,out));
    }
    else if(st==1)  //we are inside target interval
    {
        //take this value
        ret=max(ret,go(idx+1,1,in,out)+arr[idx]);
        //close interval
        ret=max(ret,go(idx+1,2,in,out));
        //dont take this value
        if(in<k)
            ret=max(ret,go(idx+1,1,in+1,out));
    }
    else    //target interval has already been processed
    {
        //take this value
        if(out<k)
            ret=max(ret,go(idx+1,2,in,out+1)+arr[idx]);
        //dont take this vale
        ret=max(ret,go(idx+1,2,in,out));
    }
    return ret;
}
int main()
{
    memset(dp,0,sizeof(dp));
    cin>>n>>k;
    for(int i=0;i<n;i++)
        cin>>arr[i];

    cout<<go(0,0,0,0);
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n, k;
int b[220], c[220];
bool cmp(int a, int b){
    return a > b;
}
int cal(int l, int r){
    int i, j, s1 = 0, s2 = 0;
    vector <int> b, c;
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
    }
    //c[i]l到r区间的,b[i]存的是剩下的元素
    sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());

    s1 = b.size(), s2 = c.size();

    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j;
    scanf("%d%d", &n, &k);
    int ans = -oo;
    for(i = 0; i < n; i++)
        scanf("%d", &a[i]);
    //暴力
    for(i = 0; i < n; i++)
        for(j = i; j < n; j++)
            ans = max(ans, cal(i, j));
    printf("%d\n", ans);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k)){
        int s = 0, m = 0, l = 0, r = 0, maxx = -oo, fu = -oo;
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu < a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > maxx ){
                r = i;
                maxx = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            maxx -= f[i];
            if(b[s1-i-1] > 0)maxx += b[s1-i-1];
        }
        if(fu < 0)maxx = fu;
        printf("%d\n", maxx);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k)){
        int s = 0, m = 0, l = 0, r = 0, max = -oo, fu = -oo;
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu < a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > max ){
                r = i;
                max = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            max -= f[i];
            if(b[s1-i-1] > 0)max += b[s1-i-1];
        }
        if(fu < 0)max = fu;
        printf("%d\n", max);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k)){
        int s = 0, m = 0, l = 0, r = 0, max = -oo, fu = -oo;
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu < a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > max ){
                r = i;
                max = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            max -= f[i];
            if(b[s1-i-1] > 0)max += b[s1-i-1];
        }
        if(fu < 0)max = fu;
        printf("%d\n", max);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n;
vector <int> b, c;
int cal(int l, int r){
    int i, j, k, s1, s2;
    b.clear(); c.clear();
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
    }
    sort(b.begin(), b.end()); sort(c.begin(), c.end());
    s1 = b.size(), s2 = c.size();
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j, k;
    while(~scanf("%d%d", &n, &k)){
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < n; i++)
            for(j = i; j < n; j++)
                ans = max(ans, cal(i, j));
        printf("%d\n", ans);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    scanf("%d%d", &n, &k);
        int s = 0, m = 0, l = 0, r = 0, max = -oo, fu = -oo;
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu < a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > max ){
                r = i;
                max = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            max -= f[i];
            if(b[s1-i-1] > 0)max += b[s1-i-1];
        }
        if(fu < 0)max = fu;
        printf("%d\n", max);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k)){
        int s = 0, m = 0, l = 0, r = 0, maxx = -oo, fu = -oo;
        memset(a, 0, sizeof(a));
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu < a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > maxx ){
                r = i;
                maxx = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            maxx -= f[i];
            if(s1-i-1 >= 0 && b[s1-i-1] > 0)maxx += b[s1-i-1];
        }
        if(fu < 0)maxx = fu;
        printf("%d\n", maxx);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n;

int cal(int l, int r){
    int i, j, k, s1, s2;
    vector <int> b, c;
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
    }
    sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());
    s1 = b.size(), s2 = c.size();
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j, k;
    scanf("%d%d", &n, &k);
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < n; i++)
            for(j = i; j < n; j++)
                ans = max(ans, cal(i, j));
        printf("%d\n", ans);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n;
int b[220], c[220];
bool cmp(int a, int b){
    return a > b;
}
int cal(int l, int r){
    int i, j, k, s1 = 0, s2 = 0;
    //vector <int> b, c;
    memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c));
    for(i = 0; i < n; i++){
        //if(i < l || i > r)b.push_back(a[i]);
        //else c.push_back(a[i]);
        if(i < l || i > r)b[s1++] = a[i];
        else c[s2++] = a[i];
    }
    //sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());
    //s1 = b.size(), s2 = c.size();
    sort(b, b + s1, cmp); sort(c, c + s2);
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j, k;
    scanf("%d%d", &n, &k);
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < n; i++)
            for(j = i; j < n; j++)
                ans = max(ans, cal(i, j));
        printf("%d\n", ans);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n, k;
int b[220], c[220];
bool cmp(int a, int b){
    return a > b;
}
int cal(int l, int r){
    int i, j, s1 = 0, s2 = 0;
    vector <int> b, c;
    //memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c));
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
        //if(i < l || i > r)b[s1++] = a[i];
        //else c[s2++] = a[i];
    }
    sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());
    s1 = b.size(), s2 = c.size();
    //sort(b, b + s1, cmp); sort(c, c + s2);
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])//swap(b[i], c[i]);???????
        {
            int t = b[i]; b[i] = c[i]; c[i] = t;
        }
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j;
    scanf("%d%d", &n, &k);
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        //for(i = 0; i < n; i++)
            //for(j = i; j < n; j++)
                ans = max(ans, cal(1, 8));
        printf("%d\n", ans);

    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int main()
{
    int n, k;
    while(~scanf("%d%d", &n, &k)){
        int s = 0, m = 0, l = 0, r = 0, max = -oo, fu = oo;
        for(int i = 0; i < n; i++){
            scanf("%d", &a[i]);
            if(fu > a[i])fu = a[i];
            s += a[i];
            if(s < 0){
                s = 0;
                l = i + 1;
            }
            if( s > max ){
                r = i;
                max = s;
            }
        }
        int b[220], f[220], s1=0, s2=0, i;
        memset(b, 0, sizeof(b));
        memset(f, 0, sizeof(f));
        for(s = i = 0; i < n; i++){
            if(i < l || i > r)b[s1++] = a[i];
            else if(a[i] <= 0)f[s2++] = a[i];
        }
        sort(b, b + s1);
        sort(f, f + s2);
        for(i = 0; i < k; i++){
            max -= f[i];
            if(b[s1-i-1] > 0)max += b[s1-i-1];
        }
        if(fu < 0)max = fu;
        printf("%d\n", max);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n;

int cal(int l, int r){
    int i, j, k, s1, s2;
    vector <int> b, c;
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
    }
    sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());
    s1 = b.size(), s2 = c.size();
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j, k;
    while(~scanf("%d%d", &n, &k)){
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < n; i++)
            for(j = i; j < n; j++)
                ans = max(ans, cal(i, j));
        printf("%d\n", ans);
    }
    return 0;
}


#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<vector>
#include<queue>
#include<cmath>
using namespace std;
#define oo 1000000
int a[220];
int n, k;
int b[220], c[220];
bool cmp(int a, int b){
    return a > b;
}
int cal(int l, int r){
    int i, j, s1 = 0, s2 = 0;
    vector <int> b, c;
    //memset(b, 0, sizeof(b)); memset(c, 0, sizeof(c));
    for(i = 0; i < n; i++){
        if(i < l || i > r)b.push_back(a[i]);
        else c.push_back(a[i]);
        //if(i < l || i > r)b[s1++] = a[i];
        //else c[s2++] = a[i];
    }
    sort(b.rbegin(), b.rend()); sort(c.begin(), c.end());
    s1 = b.size(), s2 = c.size();
    //sort(b, b + s1, cmp); sort(c, c + s2);
    for(i = 0; i < k && i < s1 && i < s2; i++){
        if(b[i] > c[i])swap(b[i], c[i]);
        //{
            //int t = b[i]; b[i] = c[i]; c[i] = t;
        //}
    }
    int ans = 0;
    for(i = 0; i < s2; i++)ans += c[i];
    return ans;
}
int main()
{
    int i, j;
    scanf("%d%d", &n, &k);
        int ans = -oo;
        for(i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for(i = 0; i < n; i++)
            for(j = i; j < n; j++)
                ans = max(ans, cal(i, j));
        printf("%d\n", ans);

    return 0;
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0;
    for (int j = 0; j < x; j++) {
        if (arr[j] >= 0) {
            int sum = 0;
            for (int i = j; i < x; i++) {
                if (arr[i] < 0) {
                    pair<int, int> id = make_pair(j, i);
                    all[idx] = make_pair(sum, id);
                    idx++;
                    break;
                }
                sum += arr[i];
            }
        }
    }
    if (idx == 0) {
        cout << arr[0];
        return 0;
    }
    sort(all, all + idx);

    /*  for (int i = 0; i < idx; i++) {
     cout << all[i].first << "   " << all[i].second.first << "     "
     << all[i].second.second << endl;
     }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if (i < all[idx - 1].second.first || i > all[idx - 1].second.second) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y--) {
        if (arr2[h - 1] > 0) {
            all[idx - 1].first += arr2[h - 1];
            h--;
        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    int maxx = -12312312;
    for (int j = 0; j < x; j++) {
        int sum2 = 0;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            sum2 += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    sort(all, all + idx);
    if (idx == 0 || all[idx - 1].first == 0) {
        cout << maxx;
        return 0;
    }
    /*for (int i = 0; i < idx; i++) {
     cout << all[i].first << "   " << all[i].second.first << "     "
     << all[i].second.second << endl;
     }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if ((i < all[idx - 1].second.first || i > all[idx - 1].second.second)
                && arr[i] > 0) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y--) {
        if (arr2[h - 1] > 0) {
            all[idx - 1].first += arr2[h - 1];
            h--;
        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
	int idx = -1;
	for (int i = 0; i < (int) s.size(); i++) {
		if (s[i] != '0') {
			idx = i;
			break;
		}
	}
	string ret = "";
	for (int i = idx; i < (int) s.size(); i++) {
		ret += s[i];
	}
	return ret;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "rt", stdin);
#endif
	fastInOut();

	/*string s;
	 cin >> s;
	 string ret = "";
	 for (int i = 0; i < (int) s.size(); i++) {
	 if (s[i] == '.')
	 ret += '0';
	 else {
	 if (s[i + 1] == '-') {
	 ret += '2';
	 i++;
	 }
	 else if (s[i + 1] == '.') {
	 ret += '1';
	 i++;
	 }
	 }
	 }cout << ret;

	 int x, y;
	 cin>>x>>y;
	 int arr[1000];
	 for (int i = 0; i < x; i++) {
	 cin >> arr[i];
	 }

	 sort(arr, arr + x);

	 for (int i = x - 1; i > x - 1 - y; i--) {

	 }
	 cout << arr[x - y];
	 */
	/*string s;
	 cin >> s;
	 string h;
	 cin >> h;
	 sort(s.begin(), s.end());

	 int idx = -1;
	 for (int i = 0; i < (int) s.size(); i++) {
	 if (s[i] != '0') {
	 idx = i;
	 break;
	 }
	 }
	 if (idx != -1)
	 swap(s[0], s[idx]);

	 fun(h);
	 if (h == s) {
	 cout << "OK";
	 } else
	 cout << "WRONG_ANSWER";*/

	int n, k, arr[10000];
	cin >> n >> k;
	for (int i = 0; i < n; i++)
		cin >> arr[i];
	int x = -10100000;
	for (int l = 0; l < n; l++) {
		for (int r = l; r < n; r++) {
			priority_queue<int> q1, q2;
			for (int i = 0; i < n; i++)
				if (i >= l && i <= r)
					q1.push(arr[i]);
				else
					q2.push(arr[i]);
			int sum = 0;
			int rem = k;
			int siz = q1.size();
			while (siz--) {
				int cur = q1.top();
				if (rem == 0 || q2.empty() || cur >= q2.top())
					q1.pop(), sum += cur;
				else
					sum += q2.top(), q2.pop(), --rem;
			}
			x = max(x, sum);
		}
	}
	cout << x;

	/*ll a, b;
	 cin >> a >> b;

	 ll re = 0;
	 while (a > b && a>0 && b>0) {
	 if ((a / b) > 0) {
	 re += (a / b);
	 ll k = a%b;
	 a = b;
	 b = k;

	 } else {
	 a = a - b;
	 if (a < b)
	 swap(a, b);
	 re++;
	 }
	 }
	 cout << re;
	 */
	/*  int a1, a2, a3, a4;
	 cin >> a1 >> a2 >> a3 >> a4;
	 string s;
	 cin >> s;

	 int arr[4];
	 memset(arr, 0, sizeof(arr));
	 for (int i = 0; i < (int) s.size(); i++) {
	 arr[(s[i] - '0') - 1]++;
	 }
	 cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

	return 0;
}

void fastInOut() {
	ios_base::sync_with_stdio(0);
	cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0' ) {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int n, k, arr[10000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int x = -10100000;
    for (int l = 0; l < n; l++) {
        for (int r = l; r < n; r++) {
            priority_queue<int> q1, q2;
            for (int i = 0; i < n; i++)
                if (i >= l && i <= r)
                    q1.push(arr[i]);
                else
                    q2.push(arr[i]);
            int sum = 0;
            int rem = k;
            int siz = q1.size();
            while (siz--) {
                int cur = q1.top();
                if (rem == 0 || q2.empty() || cur >= q2.top())
                    q1.pop(), sum += cur;
                else
                    sum += q2.top(), q2.pop(), --rem;
            }
            x = max(x, sum);
        }
    }
    cout << x;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0;
    for (int j = 0; j < x; j++) {
        if (arr[j] >= 0) {
            int sum = 0;
            for (int i = j; i < x; i++) {
                if (arr[i] < 0) {
                    pair<int, int> id = make_pair(j, i);
                    all[idx] = make_pair(sum, id);
                    idx++;
                    break;
                }
                sum += arr[i];
            }
        }
    }
    if (idx == 0){
        cout << arr[0];
        return 0;
    }
    sort(all, all + idx);

/*  for (int i = 0; i < idx; i++) {
        cout << all[i].first << "   " << all[i].second.first << "     "
                << all[i].second.second << endl;
    }*/
    int h = 0;
    for (int i = 0 ; i < x ; i++){
        if (i < all[idx-1].second.first || i > all[idx-1].second.second){
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2+h);

    while (y--) {
        all[idx-1].first += arr2[h-1];
        h--;
    }
    cout << all[idx-1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    for (int j = 0; j < x; j++) {
        //cout << j << endl;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                //j = i-2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    if (idx == 0) {
        cout << arr[0];
        return 0;
    }
    sort(all, all + idx);
/*
    for (int i = 0; i < idx; i++) {
        cout << all[i].first << "   " << all[i].second.first << "     "
                << all[i].second.second << endl;
    }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if (i < all[idx - 1].second.first || i > all[idx - 1].second.second) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y--) {
        if (arr2[h - 1] > 0) {
            all[idx - 1].first += arr2[h - 1];
            h--;
        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int n, k, arr[10000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int x = -10100000;
    for (int l = 0; l < n; l++) {
        for (int r = l; r < n; r++) {
            priority_queue<int> q1, q2;
            for (int i = 0; i < n; i++)
                if (i >= l && i <= r)
                    q1.push(arr[i]);
                else
                    q2.push(arr[i]);
            int sum =0;
            int rem = k;
            int siz = q1.size();
            while (siz--) {
                int cur = q1.top();
                if (rem == 0 || q2.empty() || cur >= q2.top())
                    q1.pop(), sum += cur;
                else
                    sum += q2.top(), q2.pop(), --rem;
            }
            x = max(x, sum);
        }
    }
    cout << x;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    for (int j = 0; j < x; j++) {
        //cout << j << endl;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                //j = i-2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    if (idx == 0 || all[idx-1].first == 0) {
        cout << arr[0];
        return 0;
    }
    sort(all, all + idx);

/*  for (int i = 0; i < idx; i++) {
        cout << all[i].first << "   " << all[i].second.first << "     "
                << all[i].second.second << endl;
    }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if (i < all[idx - 1].second.first || i > all[idx - 1].second.second) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y--) {
        if (arr2[h - 1] > 0) {
            all[idx - 1].first += arr2[h - 1];
            h--;
        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000000];

    int idx = 0, m = y;

    int maxx = -12312312;
    for (int j = 0; j < x; j++) {
        int sum2 = 0;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            sum2 += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    sort(all, all + idx);
    if (idx == 0 || all[idx - 1].first == 0) {
        cout << maxx;
        return 0;
    }
    /*for (int i = 0; i < idx; i++) {
     cout << all[i].first << "   " << all[i].second.first << "     "
     << all[i].second.second << endl;
     }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if ((i < all[idx - 1].second.first || i > all[idx - 1].second.second)
                && arr[i] > 0) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y-- && h--) {
        if (arr2[h] > 0) {
            all[idx - 1].first += arr2[h];

        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int n, k, arr[10000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int x = -10100000;
    for (int l = 0; l < n; l++) {
        for (int r = l; r < n; r++) {
            priority_queue<int> q1, q2;
            for (int i = 0; i < n; i++)
                if (i >= l && i <= r)
                    q1.push(arr[i]);
                else
                    q2.push(arr[i]);
            int sum = 0;
            int rem = k;
            int siz = q1.size();
            while (siz--) {
                int cur = q1.top();
                if (rem == 0 || q2.empty() || cur >= q2.top())
                    q1.pop(), sum += cur;
                else
                    sum += q2.top(), q2.pop(), --rem;
            }
            x = max(x, sum);
        }
    }
    cout << x;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    for (int j = 0; j < x; j++) {
        //cout << j << endl;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                //j = i-2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    sort(all, all + idx);
    if (idx == 0 || all[idx - 1].first == 0) {
            cout << arr[0];
            return 0;
        }
    /*for (int i = 0; i < idx; i++) {
        cout << all[i].first << "   " << all[i].second.first << "     "
                << all[i].second.second << endl;
    }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if (i < all[idx - 1].second.first || i > all[idx - 1].second.second) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y--) {
        if (arr2[h - 1] > 0) {
            all[idx - 1].first += arr2[h - 1];
            h--;
        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int n, k, arr[10000];
    cin >> n >> k;
    for (int i = 0; i < n; i++)
        cin >> arr[i];
    int x = -10100000;
    for (int l = 0; l < n; l++) {
        for (int r = l; r < n; r++) {
            priority_queue<int> q1, q2;
            for (int i = 0; i < n; i++)
                if (i >= l && i <= r)
                    q1.push(arr[i]);
                else
                    q2.push(arr[i]);
            int sum = 0;
            int rem = k;
            int siz = q1.size();
            while (siz--) {
                int cur = q1.top();
                if (rem == 0 || q2.empty() || cur >= q2.top())
                    q1.pop(), sum += cur;
                else
                    sum += q2.top(), q2.pop(), --rem;
            }
            x = max(mx, sum);
        }
    }
    cout << x;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    int maxx = -12312312;
    for (int j = 0; j < x; j++) {
        int sum2 = 0;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            sum2 += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    sort(all, all + idx);
    if (idx == 0 || all[idx - 1].first == 0) {
        cout << maxx;
        return 0;
    }
    /*for (int i = 0; i < idx; i++) {
     cout << all[i].first << "   " << all[i].second.first << "     "
     << all[i].second.second << endl;
     }*/
    int maa = -10010100;
    while (idx--) {
        int m = y;
        int h = 0;
        for (int i = 0; i < x; i++) {
            if ((i < all[idx].second.first || i > all[idx].second.second)
                    && arr[i] > 0) {
                arr2[h] = arr[i];
                h++;
            }
        }
        sort(arr2, arr2 + h);
        while (m--) {
            if (arr2[h - 1] > 0) {
                all[idx].first += arr2[h - 1];
                h--;
            }
        }
        if (all[idx].first > maa)
            maa = all[idx].first;
    }
    cout << maa;
    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


/*
 * Test3.cpp
 *
 *  Created on: Jun 14, 2015
 *      Author: Islam
 */

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

typedef long long ll;
typedef unsigned long long ull;

void fastInOut();

string fun(string s) {
    int idx = -1;
    for (int i = 0; i < (int) s.size(); i++) {
        if (s[i] != '0') {
            idx = i;
            break;
        }
    }
    string ret = "";
    for (int i = idx; i < (int) s.size(); i++) {
        ret += s[i];
    }
    return ret;
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "rt", stdin);
#endif
    fastInOut();

    /*string s;
     cin >> s;
     string ret = "";
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] == '.')
     ret += '0';
     else {
     if (s[i + 1] == '-') {
     ret += '2';
     i++;
     }
     else if (s[i + 1] == '.') {
     ret += '1';
     i++;
     }
     }
     }cout << ret;

     int x, y;
     cin>>x>>y;
     int arr[1000];
     for (int i = 0; i < x; i++) {
     cin >> arr[i];
     }

     sort(arr, arr + x);

     for (int i = x - 1; i > x - 1 - y; i--) {

     }
     cout << arr[x - y];
     */
    /*string s;
     cin >> s;
     string h;
     cin >> h;
     sort(s.begin(), s.end());

     int idx = -1;
     for (int i = 0; i < (int) s.size(); i++) {
     if (s[i] != '0') {
     idx = i;
     break;
     }
     }
     if (idx != -1)
     swap(s[0], s[idx]);

     fun(h);
     if (h == s) {
     cout << "OK";
     } else
     cout << "WRONG_ANSWER";*/

    int x, y;
    cin >> x >> y;
    int arr[100000];
    int arr2[100000];
    for (int i = 0; i < x; i++) {
        cin >> arr[i];
    }

    pair<int, pair<int, int> > all[1000];

    int idx = 0, m = y;

    int maxx = -12312312;
    for (int j = 0; j < x; j++) {
        int sum2 = 0;
        int sum = 0;
        for (int i = j; i < x; i++) {
            if (m == 0 && arr[i] < 0) {
                pair<int, int> id = make_pair(j, i - 1);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] > 0)
                sum += arr[i];
            sum2 += arr[i];
            if (i == x - 1) {
                pair<int, int> id = make_pair(j, i);
                all[idx] = make_pair(sum, id);
                idx++;
                m = y;
                if (sum2 > maxx)
                    maxx = sum2;
                break;
            }
            if (arr[i] < 0)
                m--;

        }
    }

    sort(all, all + idx);
    if (idx == 0 || all[idx - 1].first == 0) {
        cout << maxx;
        return 0;
    }
    /*for (int i = 0; i < idx; i++) {
     cout << all[i].first << "   " << all[i].second.first << "     "
     << all[i].second.second << endl;
     }*/
    int h = 0;
    for (int i = 0; i < x; i++) {
        if ((i < all[idx - 1].second.first || i > all[idx - 1].second.second)
                && arr[i] > 0) {
            arr2[h] = arr[i];
            h++;
        }
    }
    sort(arr2, arr2 + h);

    while (y-- && h--) {
        if (arr2[h] > 0) {
            all[idx - 1].first += arr2[h];

        }
    }
    cout << all[idx - 1].first;

    /*ll a, b;
     cin >> a >> b;

     ll re = 0;
     while (a > b && a>0 && b>0) {
     if ((a / b) > 0) {
     re += (a / b);
     ll k = a%b;
     a = b;
     b = k;

     } else {
     a = a - b;
     if (a < b)
     swap(a, b);
     re++;
     }
     }
     cout << re;
     */
    /*  int a1, a2, a3, a4;
     cin >> a1 >> a2 >> a3 >> a4;
     string s;
     cin >> s;

     int arr[4];
     memset(arr, 0, sizeof(arr));
     for (int i = 0; i < (int) s.size(); i++) {
     arr[(s[i] - '0') - 1]++;
     }
     cout << arr[0] * a1 + arr[1] * a2 + arr[2] * a3 + arr[3] * a4;*/

    return 0;
}

void fastInOut() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL), cout.tie(NULL);
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 210;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002,y;
LL ans;
bool ok=true;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << (LL)ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 210;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002;
LL ans;
bool ok=true;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << (LL)ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 210;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002;
int ans;
bool ok=true;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 202;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,ans=-1002,kk,mn=1002;
bool ok=true,q;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      ans = max(ans,sum);
    }
  }
cout << ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 205;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,mn=1002,ans=-1002;
bool ok=true;

int main() {
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < k; p++) {
        if(ll<0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]); ll--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 205;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002;
LL ans;
bool ok=true,q;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << (LL)ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 205;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002;
LL ans;
bool ok=true;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << (LL)ans;
return 0;
}


#include <cstdio>
#include <conio.h>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <iostream>

using namespace std;

const int N = 205;
typedef long long LL;

int x[N],x1[N],x2[N];
int n,k,sum,l,ll,kk,mn=1002,lll;
LL ans;
bool ok=true;

int main() {
//freopen("input.txt","r",stdin);
  cin >> n >> k;
  for(int i = 0; i < n; i++) {
   cin >> x[i];
   if(x[i]<mn) mn=x[i];
   if(x[i]>=0) ok=false;
  }
 if(ok==true) {printf("%d",mn); return 0;}

  for(int i = 0; i < n; i++) {
    for(int j = i; j < n; j++) {
      l=ll=0; kk=k;
      for(int p = i; p <= j; p++,l++) x1[l]=x[p];
      for(int p = 0; p < i; p++,ll++) x2[ll]=x[p];
      for(int p = j + 1; p < n; p++,ll++) x2[ll]=x[p];
      sort(x1,x1+l); sort(x2,x2+ll); ll--;
      for(int p = 0; p < l; p++) {
        if(kk==0) break;
        if(x1[p]<x2[ll]) {
          swap(x1[p],x2[ll]);
          ll--; kk--;
        }
      }
      sum=0;
      for(int p = 0; p < l; p++)
       sum+=x1[p];
      if(sum>ans) ans=sum;
    }
  }
cout << (LL)ans;
return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[10000];
int sumax;
void dfs(int s, int L, int R, int k)
{
    sumax=max(sumax,s);
    if(k<=0)return ;
    int q1=0x7fffffff,q2,q3=-0x7fffffff,q4;
   for(int i = L; i <= R; i++)if(q1>a[i]){q1=a[i];q2=i;}
   for(int i = 0; i < L; i++)if(q3<a[i]){q3=a[i];q4=i;}
    for(int i = R+1; i < n; i++)if(q3<a[i]){q3=a[i];q4=i;}
    if(q1>0&&q3<0) return ;
    if(q1<0&&q3>0)
    {
        swap(a[q2],a[q4]);
        s+=q3-q1;
        dfs(s,L,R,k-1);
        swap(a[q2],a[q4]);
    }
    else if(q1<0&&q3<0)
    {
        if(R-L==0)return ;
        swap(a[q2],a[R]);
        s+=-q1;
        dfs(s,L,R-1,k-1);
        swap(a[q2],a[R]);
    }
    else if(q1>0&&q3>0)
    {
        if(L-1>=0)
        {
            swap(a[q4],a[L-1]);
            int id=L-1,b=0,c=0,l;
            while(id>=0)
            {
                b+=a[id];
                if(c<b){l=id;c=b;}
                id--;
            }
            dfs(s+c,l,R,k-1);
            swap(a[q4],a[L-1]);
        }
        if(R+1<n)
        {
            swap(a[q4],a[R+1]);
            int id=R+1,b=0,c=0,r;
            while(id<n)
            {
                b+=a[id];
                if(c<b){r=id;c=b;}
                id++;
            }
            dfs(s+c,L,r,k-1);
            swap(a[q4],a[R+1]);
        }
    }
}
int main()
{
    int k;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i = 0; i < n; i++)scanf("%d",&a[i]);
        int L,R;
//        L=-1,l=0,R,sumax=0,sum=0;
//        for(int i = 0; i < n; i++)
//        {
//            sum+=a[i];
//            if(sumax<sum){sumax=sum;R=i;L=l;}
//            if(sum<0){l=i+1;sum=0;}
//        }
//       printf("sum=%d l=%d r=%d\n",sumax,L,R);
//       if(sumax==0&&L==-1)
//       {
//           int Max=-0x7fffffff;
//           for(int i = 0; i < n; i++)Max=max(Max,a[i]);
//           printf("%d\n",Max);
//           continue;
//       }
        sumax=-0x7fffffff;
        int son[10000];son[0]=a[0];
        for(int i = 1; i < n; i++)son[i]=a[i]+son[i-1];
        for(L=0;L<n;L++)
        for(R=L;R<n;R++)
        {
            int tmp;
            tmp=son[R]-son[L]+a[L];
            dfs(tmp,L,R,k);
            //if(sumax==6031)printf("l=%d r=%d\n",L,R);
        }
       printf("%d\n",sumax);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n;
int a[10000];
int sumax,sum;
void dfs(int s, int L, int R, int k)
{
    sumax=max(sumax,s);
    if(k<=0)return ;
    int q1=0x7fffffff,q2,q3=-0x7fffffff,q4;
   for(int i = L; i <= R; i++)if(q1>a[i]){q1=a[i];q2=i;}
   for(int i = 0; i < L; i++)if(q3<a[i]){q3=a[i];q4=i;}
    for(int i = R+1; i < n; i++)if(q3<a[i]){q3=a[i];q4=i;}
    if(q1>0&&q3<0) return ;
    if(q1<0&&q3>0)
    {
        swap(a[q2],a[q4]);
        s+=q3-q1;
        dfs(s,L,R,k-1);
    }
    else if(q1<0&&q3<0)
    {
        if(R-L==0)return ;
        swap(a[q2],a[R]);
        R--;
        s+=-q1;
        dfs(s,L,R,k-1);
    }
    else if(q1>0&&q3>0)
    {
        if(L-1>=0)
        {
            swap(a[q4],a[L-1]);
            int id=L-1,b=0,c=0,l;
            while(id>=0)
            {
                b+=a[id];
                if(c<b){l=id;c=b;}
                id--;
            }
            dfs(s+c,l,R,k-1);
            swap(a[q4],a[L-1]);
        }
        if(R+1<n)
        {
            swap(a[q4],a[R+1]);
            int id=R+1,b=0,c=0,r;
            while(id<n)
            {
                b+=a[id];
                if(c<b){r=id;c=b;}
                id++;
            }
            dfs(s+c,L,r,k-1);
            swap(a[q4],a[R+1]);
        }
    }
}
int main()
{
    int k;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i = 0; i < n; i++)scanf("%d",&a[i]);
        int L,R;
//        L=-1,l=0,R,sumax=0,sum=0;
//        for(int i = 0; i < n; i++)
//        {
//            sum+=a[i];
//            if(sumax<sum){sumax=sum;R=i;L=l;}
//            if(sum<0){l=i+1;sum=0;}
//        }
//       printf("sum=%d l=%d r=%d\n",sumax,L,R);
//       if(sumax==0&&L==-1)
//       {
//           int Max=-0x7fffffff;
//           for(int i = 0; i < n; i++)Max=max(Max,a[i]);
//           printf("%d\n",Max);
//           continue;
//       }
        sumax=-0x7fffffff;
        int son[10000];son[0]=a[0];
        for(int i = 1; i < n; i++)son[i]=a[i]+son[i-1];
        for(L=0;L<n;L++)
        for(R=L;R<n;R++)
        {
            int tmp;
            tmp=son[R]-son[L]+a[L];
            dfs(tmp,L,R,k);
        }
       printf("%d\n",sumax);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,k;
int a[10000];
int sumax,sum;
void dfs(int s, int L, int R, int k)
{
    sumax=max(sumax,s);
    if(k<=0)return ;
    int q1=0x7fffffff,q2,q3=-0x7fffffff,q4;
   for(int i = L; i <= R; i++)if(q1>a[i]){q1=a[i];q2=i;}
   for(int i = 0; i < L; i++)if(q3<a[i]){q3=a[i];q4=i;}
    for(int i = R+1; i < n; i++)if(q3<a[i]){q3=a[i];q4=i;}
    if(q1>0&&q3<0) return ;
    if(q1<0&&q3>0)
    {
        swap(a[q2],a[q4]);
        s+=q3-q1;
        dfs(s,L,R,k-1);
    }
    else if(q1<0&&q3<0)
    {
        swap(a[q2],a[R]);
        R--;
        s+=-q1;
        dfs(s,L,R,k-1);
    }
    else if(q1>0&&q3>0)
    {
        if(L-1>=0)
        {
            swap(a[q4],a[L-1]);
            int id=L-1,b=0,c=0,l;
            while(id>=0)
            {
                b+=a[id];
                if(c<b){l=id;c=b;}
                id--;
            }
            dfs(s+c,l,R,k-1);
            swap(a[q4],a[L-1]);
        }
        if(R+1<n)
        {
            swap(a[q4],a[R+1]);
            int id=R+1,b=0,c=0,r;
            while(id<n)
            {
                b+=a[id];
                if(c<b){r=id;c=b;}
                id++;
            }
            dfs(s+c,L,r,k-1);
            swap(a[q4],a[R+1]);
        }
    }
}
int main()
{
    while(~scanf("%d%d",&n,&k))
    {
        for(int i = 0; i < n; i++)scanf("%d",&a[i]);
        int L,R,l;
        L=-1,l=0,R,sumax=0,sum=0;
        for(int i = 0; i < n; i++)
        {
            sum+=a[i];
            if(sumax<sum){sumax=sum;R=i;L=l;}
            if(sum<0){l=i+1;sum=0;}
        }
       //printf("sum=%d l=%d r=%d\n",sumax,L,R);
       if(sumax==0&&L==-1)
       {
           int Max=-0x7fffffff;
           for(int i = 0; i < n; i++)Max=max(Max,a[i]);
           printf("%d\n",Max);
           continue;
       }
        dfs(sumax,L,R,k);
       printf("%d\n",sumax);
    }
    return 0;
}


#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
    int a[100000];
    int n,k;
    while(~scanf("%d%d",&n,&k))
    {
        for(int i = 0; i < n; i++)scanf("%d",&a[i]);
        int L=-1,l=0,R,sumax=0,sum=0;
        for(int i = 0; i < n; i++)
        {
            sum+=a[i];
            if(sumax<sum){sumax=sum;R=i;L=l;}
            if(sum<0){l=i+1;sum=0;}
        }
       // printf("sum=%d l=%d r=%d\n",sumax,L,R);
       if(sumax==0&&L==-1)
       {
           int Max=-0x7fffffff;
           for(int i = 0; i < n; i++)Max=max(Max,a[i]);
           printf("%d\n",Max);
           continue;
       }
       int vis[100000];
       memset(vis,0,sizeof(vis));
       while(k)
       {
           int q1=0x7fffffff,q2,q3=-0x7fffffff,q4;
           for(int i = L; i <= R; i++)if(q1>a[i]&&vis[i]==0){q1=a[i];q2=i;}
           for(int i = 0; i < L; i++)if(q3<a[i]&&vis[i]==0){q3=a[i];q4=i;}
            for(int i = R+1; i < n; i++)if(q3<a[i]&&vis[i]==0){q3=a[i];q4=i;}
            if(q1>0&&q3<0)break;
            if(q1<0)vis[q2]=1;
            if(q1>0)q1=0;
            if(q3>0)vis[q4]=1;
            if(q3<0)q3=0;
            sumax+=q3-q1;
            k--;
       }
       printf("%d\n",sumax);
    }
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
int main()
{
    int i;
    int n,k,d,kk,a[205],m=-1337;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++){
        scanf("%d",&a[i])
        }
    for(i=0;i<n;i++){
        for(d=i;d<n;d++){
            vector<int>u,v;
            for(kk=0;kk<n;kk++)
                if(kk<i || kk>d){
                    v.push_back(a[kk]);
                    }
                else u.push_back(a[kk]);
            sort(v.rbegin(),v.rend());
            for(kk=0;kk<k&&kk<v.size();kk++){
                u.push_back(v[kk]);
                }
            sort(u.rbegin(),u.rend());
            int sum=0;
            for(kk=0;kk<=d-i;kk++) sum+=u[kk]{
                m=max(m,sum);
                }
        }
        }
    printf("%d\n",m);
    return 1;
}


#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,abm,mmx,tune=native")
#pragma comment(linker, "/STACK:2759095000")
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<cstdlib>
#include<cstdint>
#include<cmath>
#include<algorithm>
#include<iostream>
#include<fstream>
#include<vector>
#include<string>
#include<cstring>
#include<map>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<sstream>
#include<numeric>
#include<random>
#include<functional>
#include<unordered_set>
#include<unordered_map>
#include<stack>

using namespace std;

typedef unsigned int ull;
typedef long long ll;
#define int ll
typedef int itn;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ld, ld> pdd;
typedef pair<int, char> pic;
typedef pair<ll, pii> piii;
#define xx first
#define yy second
#define zz second.second
#define mp make_pair
#define y1 oshfkfsldhs
#define union jfghjdghdjhgjhdjgh
#define all(x) (x).begin(), (x).end()

const ll MOD = 1e9 + 7;
const ll MOD1 = 7340033;
const ll BAS = 2500;
const ll dx[] = { 0, 0, 1, -1 };
const ll dy[] = { 1, -1, 0, 0 };
const char dc[] = { 'R', 'L', 'D', 'U' };
const ll INF = 1e9;
const double EPS = 1e-5;
const long double PI = 3.14159265358979323846;
const int SZ = 2000;
const ll MAXN = 2e5 + 10;

#ifdef _DEBUG
int __builtin_popcount(int x) { return x ? (__builtin_popcount(x >> 1) + (x & 1)) : 0; }
#endif

ll gcd(ll x, ll y)
{
	if (x == 0)
		return y;
	return gcd(y % x, x);
}

ll n, m, k;
ll a[MAXN], b[MAXN];
string s, t;

vector<vector<int>> answers;

signed main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cout.precision(16);
	srand(89398);
#ifdef _DEBUG
	auto _ = freopen("input.txt", "r", stdin);
	_ = freopen("output.txt", "w", stdout);
#else
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//freopen("tikal.in", "r", stdin);
	//freopen("tikal.out", "w", stdout);
#endif
	cin >> n >> k;
	cin >> s;
	ll R = 0;
	ll sw = 0;
	for (int i = 0; i < n; i++)
	{
		if (s[i] == 'R')
			R++;
		else
			sw += R;
	}
	if (sw < k)
	{
		cout << -1;
		return 0;
	}
	for (; 1;)
	{
		answers.push_back({});
		for (int i = 0; i < n - 1; i++)
		{
			if (s[i] == 'R' && s[i + 1] == 'L')
			{
				swap(s[i], s[i + 1]);
				answers.back().push_back(i);
				i++;
			}
		}
		if (answers.back().size() == 0)
			break;

	}
	answers.pop_back();
	if (answers.size() > k)
	{
		cout << -1;
		return 0;
	}
	bool f = answers.size() < k;
	for (int i = 0; i < answers.size(); i++)
	{
		if(k > answers.size() - i)
			for (int j = 0; j < answers[i].size(); j++)
			{
				if (k > answers.size() - i)
				{
					cout << "1 " << answers[i][j] + 1 << "\n";
					k--;
					continue;
				}
				else
				{
					cout << answers[i].size() - j << " ";
					for (int t = j; t < answers[i].size(); t++)
						cout << answers[i][t] + 1 << " " ;
					cout << "\n";
					k--;
					break;
				}
			}
		else
		{
			cout << answers[i].size() << " ";
			for (int p : answers[i])
				cout << p + 1 << " " ;
			cout << "\n";
			k--;
		}
	}
}


#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>

using namespace std;
int main() {

#ifdef _DEBUG
		freopen("input.txt", "r", stdin);
#else
		//freopen("unequal.in", "r", stdin);
		//freopen("unequal.out", "w", stdout);
#endif
	int n, k;
	scanf("%d %d ",&n, &k);
	vector<int> anus;
	vector<bool> a(n);
	for (int i = 0; i < n; i++)
	{
		char c;
		scanf("%c",&c);
		if (c == 'R')
			a[i] = 1;
		else
			a[i] = 0;
	}
	bool flag = true;
	int cnt = 0;
	while (flag)
	{
		flag = false;
		for (int i = 1; i < n; i++)
		{
			if (a[i - 1] && !a[i])
			{
				flag = true;
				anus.push_back(i);
				a[i - 1] = !a[i-1];
				a[i] = !a[i];
				i++;
				cnt++;
			}
		}
		anus.push_back(0);
	}
	if (cnt < k)
	{
		printf("-1");
		return 0;
	}

	int ind = 0;
	vector<vector<int>> ans(k);
	int cur = 0;
	for (int i = 0; i < k; i++)
	{

		while (ind < anus.size() && anus[ind] && cnt+i>=k)
		{
			cur=i;
			ans[i].push_back(anus[ind++]);
			cnt--;
		}
		if (ind < anus.size() && anus[ind] == 0)
			ind++;
	}

	if(cnt)
	{
		printf("-1");
		return 0;
	}
	for (auto v : ans)
	{
		printf("%d ",v.size());
		for (auto x : v)
			printf("%d ",x);
		printf("\n");
	}

	return 0;
}


#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[3005];

void solve()
{
    int n, K;
    scanf("%d%d%s", &n, &K, str);

    vector<vector<int> > v;
    int cnt = 0;
    int i;
    while (1) {
        vector<int> v0;
        for (i = 0; i < n-1; i++) {
            if (str[i] == 'R' && str[i + 1] == 'L') {
                v0.push_back(i);
                str[i] = 'L';
                str[i + 1] = 'R';
                i++;
                cnt++;
            }
        }
        if (v0.size() == 0) break;
        v.push_back(v0);
    }

    int siz = (int)v.size();
    if (K < siz || cnt < K) {
        printf("-1\n");
    }
    int add = K - siz;
    for (i = 0; i < siz; i++) {
        vector<int>& v0 = v[i];
        int cnt0 = 0;
        while (add > 0 && cnt0 < (int)v0.size()) {
            printf("1 %d\n", v0[cnt0]+1);
            cnt0++;
        }
        if (cnt0 < (int)v0.size()) {
            printf("%d ", (int)v0.size() - cnt0);
            int k;
            for (k = cnt0; k < (int)v0.size(); k++) {
                printf("%d", v0[k]+1);
                if (k < (int)v0.size() - 1) printf(" ");
            }
            printf("\n");
        }
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[3005];

void solve()
{
    int n, K;
    scanf("%d%d%s", &n, &K, str);

    vector<vector<int> > v;
    int cnt = 0;
    int i;
    while (1) {
        vector<int> v0;
        for (i = 0; i < n-1; i++) {
            if (str[i] == 'R' && str[i + 1] == 'L') {
                v0.push_back(i);
                str[i] = 'L';
                str[i + 1] = 'R';
                i++;
                cnt++;
            }
        }
        if (v0.size() == 0) break;
        v.push_back(v0);
    }

    int siz = (int)v.size();
    if (K < siz || cnt < K) {
        printf("-1\n"); return;
    }
    int add = K - siz;
    for (i = 0; i < siz; i++) {
        vector<int>& v0 = v[i];
        int cnt0 = 0;
        while (add > 0 && cnt0 < (int)v0.size()) {
            printf("1 %d\n", v0[cnt0]+1);
            cnt0++;
        }
        if (cnt0 < (int)v0.size()) {
            printf("%d ", (int)v0.size() - cnt0);
            int k;
            for (k = cnt0; k < (int)v0.size(); k++) {
                printf("%d", v0[k]+1);
                if (k < (int)v0.size() - 1) printf(" ");
            }
            printf("\n");
        }
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}


#include <cstdio>
#include <string>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <cassert>
#include <numeric>
#pragma warning(disable:4996)

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF  9223300000000000000
#define LINF2 1223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;

using namespace std;

char str[3005];

void solve()
{
    int n, K;
    scanf("%d%d%s", &n, &K, str);

    vector<vector<int> > v;
    int cnt = 0;
    int i;
    while (1) {
        vector<int> v0;
        for (i = 0; i < n-1; i++) {
            if (str[i] == 'R' && str[i + 1] == 'L') {
                v0.push_back(i);
                str[i] = 'L';
                str[i + 1] = 'R';
                i++;
                cnt++;
            }
        }
        if (v0.size() == 0) break;
        v.push_back(v0);
    }

    int siz = (int)v.size();
    if (K < siz || cnt < K) {
        printf("-1\n"); return;
    }
    int add = K - siz;
    for (i = 0; i < siz; i++) {
        vector<int>& v0 = v[i];
        int cnt0 = 0;
        while (add > 0 && cnt0 < (int)v0.size()) {
            printf("1 %d\n", v0[cnt0]+1);
            cnt0++;
            add--;
        }
        if (cnt0 < (int)v0.size()) {
            printf("%d ", (int)v0.size() - cnt0);
            int k;
            for (k = cnt0; k < (int)v0.size(); k++) {
                printf("%d", v0[k]+1);
                if (k < (int)v0.size() - 1) printf(" ");
            }
            printf("\n");
        }
    }

    return;
}

int main(int argc, char* argv[])
{
#if 1
    solve();
#else
    int T;
    scanf("%d", &T);
    int t;
    for(t=0; t<T; t++) {
        //printf("Case #%d: ", t+1);
        solve();
    }
#endif
    return 0;
}