#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//name[i][j]-> vvl name(i,vl(j))
//map<int,int>mp
//余りを切り上げる =>  (a + b - 1) / b 

signed main(){
	ll n,k; cin>>n>>k;
	vl a(n);
	rep(i,0,n) cin>>a[i];
	rep(q,0,k){
		vl b(n+1);
		rep(i,0,n){
			ll s=max((ll)0,(i-a[i]));
			ll t=min(i+a[i]+1,n);
			b[s]++; b[t]--;
		}
		rep(i,1,n+1) b[i]+=b[i-1];
		b.pop_back();
		if(a==b) break;
		a=b;
	}
	rep(i,0,n) cout<<a[i]<<" ";
	
	return 0;
}
#include <bits/stdc++.h>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
	int n, k;
	cin >> n >> k;
	vector<int> v(n);
	for(int i = 0; i < n; ++i)
	{
		cin >> v[i];
	}

	ll ans = 0;
	for(int get_num = min(k, n); get_num >= 0; --get_num)
	{
		for(int start = -get_num; start <= 0; ++start)
		{
			ll sum = 0;
			vector<int> may_erase;
			for(int i = 0; i < get_num; ++i)
			{
				int val = v[start + i < 0 ? start + i + n : start + i];
				sum += val;
				if (val < 0) may_erase.emplace_back(val);
			}

			sort(may_erase.begin(), may_erase.end());
			int erase_num = min((int)may_erase.size(), k - get_num);
			ll erase_sum = 0;
			for(int i = 0; i < erase_num; ++i)
			{
				erase_sum += may_erase[i];
			}
			// cout << get_num << " " << start << " : " << sum << " - " << -erase_sum << endl;
			ans = max(ans, sum - erase_sum);
		}
	}
	cout << ans;



}

int main()
{
	fastio;
	solve();

	return 0;
}