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

typedef long long ll;

const int N = 1e5 + 5;
ll a[N], tedad[N];

int main()
{
	int n, m;
	cin >> n >> m;
	int f = 1;
	for (int i = 0 ; i < n ; i ++)
	{
		cin >> a[i];
		if (a[i] != 0) f = 0;
	}
	if (f)
	{
		cout << 0;
		return 0;
	}
	if (n == 1)
	{
		if (a[0] == 0)
		{
			cout << 0;
			return 0;
		}
		ll t = 1;
		t += a[0] / m;
		if (a[0] % m != 0) t++;
		cout << t;
		return 0;
	}
	ll t = 1;
	tedad[0] = m;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			if (a[0] == 0)
			{
				t++;
				tedad[1] = tedad[0];
				continue;
			}
			t += a[0] / tedad[0];
			t++;
			a[0] %= tedad[0];
			ll x = tedad[0] - a[0];
			tedad[0] = a[0];
			tedad[1] = x;
			continue;
		}
		if (i == n - 1)
		{
			if (a[n-1] == 0)
			{
				continue;
			}
			a[n - 1] -= tedad[n - 1];
			if (a[n - 1] <= 0)
			{
				t++;
				continue;
			}
			t++;
			tedad[n-1] += tedad[n-2];
			t += a[n - 1] / tedad[n - 1];
			if (a[n - 1] % tedad[n - 1] != 0) t ++;
			continue;
		}
		if (a[i] == 0)
		{
			t++;
			tedad[i + 1] += tedad[i];
			tedad[i] += tedad[i-1];
			continue;
		}
		a[i] -= tedad[i];
		if (a[i] <= 0)
		{
			t++;
			tedad[i+1] += tedad[i] - a[i];
			tedad[i] = a[i];
			tedad[i] += tedad[i - 1];
			continue;
		}
		t++;
		tedad[i] += tedad[i-1];
		t += a[i] / tedad[i];
		a[i] %= tedad[i];
		if (a[i] == 0)
		{
			t++;
			tedad[i+1] += tedad[i];
			tedad[i] = 0;
			continue;
		}
		t++;
		tedad[i+1] += tedad[i] - a[i];
		tedad[i] = a[i];
	}
	cout << t;
}


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

typedef long long ll;

const int N = 1e5 + 5;
ll a[N], ttt[N];
ll* tedad = ttt + 1;

int main()
{
	int n, m;
	cin >> n >> m;
	int f = 1;
	int mx_indx = -1;
	for (int i = 0 ; i < n ; i ++)
	{
		cin >> a[i];
		if (a[i] != 0)
		{
			f = 0;
			mx_indx = i;
		}
	}
	if (f)
	{
		cout << 0;
		return 0;
	}
	if (n == 1)
	{
		if (a[0] == 0)
		{
			cout << 0;
			return 0;
		}
		ll t = 1;
		t += a[0] / m;
		if (a[0] % m != 0) t++;
		cout << t;
		return 0;
	}
	ll t = 1;
	tedad[0] = m;
	for (int i = 0; i < n; i++)
	{
		if (mx_indx < i) break;
		if (a[i] < tedad[i])
		{
			t++;
			tedad[i+1] += tedad[i] - a[i];
			tedad[i] = a[i];
			tedad[i] += tedad[i-1];
			continue;
		}
		a[i] -= tedad[i];
		t++;
		tedad[i] += tedad[i-1];
		t += a[i] / tedad[i];
		a[i] %= tedad[i];
		tedad[i+1] += tedad[i] - a[i];
		tedad[i] = a[i];
		if (mx_indx > i || a[i] != 0) t++;
	}
	cout << t;
}


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

typedef long long ll;

const int N = 1e5 + 5;
ll a[N], tedad[N];

int main()
{
	int n, m;
	cin >> n >> m;
	for (int i = 0 ; i < n ; i ++)
	{
		cin >> a[i];
	}
	if (n == 1)
	{
		if (a[0] == 0)
		{
			cout << 0;
			return 0;
		}
		ll t = 1;
		t += a[0] / m;
		if (a[0] % m != 0) t++;
		cout << t;
		return 0;
	}
	ll t = 1;
	tedad[0] = m;
	for (int i = 0; i < n; i++)
	{
		if (i == 0)
		{
			if (a[0] == 0)
			{
				t++;
				tedad[1] = tedad[0];
				continue;
			}
			t += a[0] / tedad[0];
			t++;
			a[0] %= tedad[0];
			ll x = tedad[0] - a[0];
			tedad[0] = a[0];
			tedad[1] = x;
			continue;
		}
		if (i == n - 1)
		{
			if (a[n-1] == 0)
			{
				continue;
			}
			a[n - 1] -= tedad[n - 1];
			if (a[n - 1] <= 0)
			{
				t++;
				continue;
			}
			t++;
			tedad[n-1] += tedad[n-2];
			t += a[n - 1] / tedad[n - 1];
			if (a[n - 1] % tedad[n - 1] != 0) t ++;
			continue;
		}
		if (a[i] == 0)
		{
			t++;
			tedad[i + 1] += tedad[i];
			tedad[i] += tedad[i-1];
			continue;
		}
		a[i] -= tedad[i];
		if (a[i] <= 0)
		{
			t++;
			tedad[i+1] += tedad[i] - a[i];
			tedad[i] = a[i];
			tedad[i] += tedad[i - 1];
			continue;
		}
		t++;
		tedad[i] += tedad[i-1];
		t += a[i] / tedad[i];
		a[i] %= tedad[i];
		if (a[i] == 0)
		{
			t++;
			tedad[i+1] += tedad[i];
			tedad[i] = 0;
			continue;
		}
		t++;
		tedad[i+1] += tedad[i] - a[i];
		tedad[i] = a[i];
	}
	cout << t;
}


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

typedef long long ll;

int main()
{
	ll n, m;
	cin >> n >> m;
	ll maj = 0;
	ll mx_indx = 0;
	for (int i = 0;i < n; i++)
	{
		ll x;
		cin >> x;
		maj += x;
		if (x) mx_indx = i + 1;
	}
	ll t = maj / (m);
	if (maj % m != 0) t++;
	cout << t + mx_indx;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n,m,a[100100];

bool can(LL ti){
	LL idx = n,tiLeft,take,pile[100100];
	for(int i=1;i<=n;i++) pile[i]=a[i];
	for(int i=1;i<=m;i++){
		tiLeft = ti-idx;
		while(tiLeft>0 && idx>0){
			take = min(tiLeft,pile[idx]);
			pile[idx]-=take;
			tiLeft-=take;
			if(pile[idx]==0) idx--;
		}
	}
	for(int i=1;i<=n;i++) if(pile[i]) return false;
	return true;
}

LL bs(LL l,LL r){
	if(l>r) return 1e18;
	LL mid = (l+r)/2;
	if(can(mid)) return min(mid,bs(l,mid-1));
	return bs(mid+1,r);
}

int main() {
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",bs(0,10));
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n,m,a[100100];

bool can(LL ti){
	LL idx = n,tiLeft,take,pile[100100];
	for(int i=1;i<=n;i++) pile[i]=a[i];
	for(int i=1;i<=m;i++){
		tiLeft = ti-idx;
		while(tiLeft>0 && idx>0){
			take = min(tiLeft,pile[idx]);
			pile[idx]-=take;
			tiLeft-=take;
			if(pile[idx]==0) idx--;
		}
	}
	for(int i=1;i<=n;i++) if(pile[i]) return false;
	return true;
}

LL bs(LL l,LL r){
	if(l>r) return 1e18;
	LL mid = (l+r)/2;
	if(can(mid)) return min(mid,bs(l,mid-1));
	return bs(mid+1,r);
}

int main() {
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",bs(0,1e18));
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n,m,a[100100];

bool can(LL ti){
	LL idx = n,tiLeft,take,pile[100100];
	for(int i=1;i<=n;i++) pile[i]=a[i];
	for(int i=1;i<=m;i++){
		while(pile[idx]==0) idx--;
		tiLeft = ti-idx;
		while(tiLeft>0 && idx>0){
			take = min(tiLeft,pile[idx]);
			pile[idx]-=take;
			tiLeft-=take;
			while(pile[idx]==0) idx--;
		}
	}
	for(int i=1;i<=n;i++) if(pile[i]) return false;
	return true;
}

LL bs(LL l,LL r){
	if(l>r) return 1e18;
	LL mid = (l+r)/2;
	if(can(mid)) return min(mid,bs(l,mid-1));
	return bs(mid+1,r);
}

int main() {
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",bs(0,1e18));
	return 0;
}


#include <bits/stdc++.h>
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define sc second
using namespace std;

LL n,m,a[100100];

bool can(LL ti){
	LL idx = n,tiLeft,take,pile[100100];
	for(int i=1;i<=n;i++) pile[i]=a[i];
	for(int i=1;i<=m;i++){
		while(pile[idx]==0) idx--;
		tiLeft = ti-idx;
		while(tiLeft>0 && idx>0){
			take = min(tiLeft,pile[idx]);
			pile[idx]-=take;
			tiLeft-=take;
			while(pile[idx]==0) idx--;
		}
	}
	for(int i=1;i<=n;i++) if(pile[i]) return false;
	return true;
}

LL bs(LL l,LL r){
	if(l>r) return 1e18;
	LL mid = (l+r)/2;
	if(can(mid)) return min(mid,bs(l,mid-1));
	return bs(mid+1,r);
}

int main() {
	scanf("%lld %lld",&n,&m);
	for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
	printf("%lld\n",bs(0,16));
	return 0;
}


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

long long n,m,a[(int)1e5 + 5],b[(int)1e5+5];

bool check(long long t){
    for(int i=0;i<n;i++){
        b[i] = a[i];
    }
    // printf("\n");
    long long np = 0;

    long long p=t;
    for(int i=n-1;i>=0;i--){
        if(b[i]){
            p -= (i+1);
            if(p <= 0)return 0;
            if(np > m)return 0;

            while(p > 0 && i >= 0){
                if(p > b[i]){
                    // printf("people: %d , nowplace: %d , restlife : %d\n",np,i,p);
                    p -= b[i];
                    i--;
                }
                else{
                    // printf("people: %d , nowplace: %d , restlife : %d\n",np,i,p);
                    b[i] -= p;
                    i++;
                    np++;
                    p = t;
                    break;
                }
            }
        }
    }

    if(np < m){
        return 1;
    }
    else{
        if(np == m){
            if(p == t)return 1;
            else return 0;
        }
        else{
            return 0;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);

    cin>>n>>m;
    for(int i;i<n;i++){
        cin>>a[i];
    }

    long long l = 0,r = 100000000000;
    while(l + 1 < r){
        int mid = (r+l)/2;
        if(check(mid))r = mid;
        else l = mid;
    }

    if(check(l)){
        cout<<l<<endl;
    }
    else{
        cout<<r<<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[100005]= {0};
long long b[100005]= {0};
int main()
{
	ios::sync_with_stdio(false);
	//cin.tie(0);
	long long n,m;
	cin>>n>>m;
	long long t=n*(m+2);
	for (long long i=1; i<=n; i++)
	{
		cin>>a[i];
		t+=a[i];
	}
	long long l=1,r=t;
	while (l<r)
	{
		long long mid=l+(r-l)/2,lo=0;
		memcpy(b,a,(n+2)*sizeof(long long));
		for (long long i=1; i<=m; i++)
		{
			long long time=mid-lo,temp;
			while (time)
			{
				temp=lo;
				if (b[temp]==0)
				{
					time--;
					temp++;
				}
				else
				{
					if (time>b[temp])
					{
						time-=b[temp];
						b[temp]=0;
					}
					else
					{
						b[temp]-=time;
						time=0;
					}
				}
				lo=temp;
				if (b[n]==0) break;
			}
		}
		if (b[n]==0) r=mid;
		else l=mid+1;
	}
	cout<<r;
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX_N = 1e5+50;
ll a[MAX_N],b[MAX_N],n,m;
bool judge(ll num){
    memcpy(b,a,sizeof a);
    int pos = 0;
    for(int i=1;i<=m;i++){
        ll tmp = num-pos;
        while(tmp>0&&pos<=n){
            ll minu = min(b[pos],tmp);
            b[pos]-=minu;
            tmp-=minu;
            if(b[pos]==0)pos++,tmp--;
        }
    }
    for(int i=1;i<=n;i++){
        if(b[i])return false;
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    ll l = 0,r = 1e15,ans = 0;
    while(l<=r){
        ll mid = l+(r-l)/2;
        //cout<<mid<<endl;
        if(!judge(mid)) l = mid+1;
        else r = mid-1,ans = mid;
    }
    cout<<ans<<endl;
	return 0;
}


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

inline void wait()
{
    getchar();
    getchar();
}

const int N = 1e5 + 5;
int a[N], b[N], m, n;

int ok(long long x)
{
    for(int i = 1; i <= n; i++)
        b[i] = a[i];
    int pos = n;
    for(int i = 0; pos && i < m; i++)
    {
        while(pos && b[pos] == 0)
            pos--;
        long long lft = x - pos;
        while(pos)
        {
            if(b[pos] <= lft)
            {
                lft -= b[pos];
                b[pos--] = 0;
            }
            else
            {
                b[pos] -= lft;
                lft = 0;
                break;
            }
        }
    }
    return pos == 0;

}

int main()
{
    scanf("%d%d", &n, &m);
    int L = 0, R = n + 1;
    for(int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        R += a[i];
    }

    while(L < R)
    {
        long long mid = (L + R) / 2;
        if(ok(mid))
            R = mid;
        else
            L = mid + 1;
    }
    printf("%d\n", L);

   // wait();
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAX_N = 1e5+50;
int a[MAX_N],b[MAX_N],n,m;
bool judge(int num){
    memcpy(b,a,sizeof a);
    int pos = 0;
    for(int i=1;i<=m;i++){
        int tmp = num-pos;
        while(tmp>0&&pos<=n){
            int minu = min(b[pos],tmp);
            b[pos]-=minu;
            tmp-=minu;
            if(b[pos]==0)pos++,tmp--;
           //if(num==5)cout<<"人："<<i<<" 剩下："<<tmp<<" 位置："<<pos<<" 当前减去"<<minu<<" "<<b[pos]<<endl;
        }
    }
    for(int i=1;i<=n;i++){
        if(b[i])return false;
    }
    return true;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }
    int l = 0,r = INT_MAX,ans = 0;
    while(l<=r){
        int mid = l+(r-l)/2;
        //cout<<mid<<endl;
        if(!judge(mid)) l = mid+1;
        else r = mid-1,ans = mid;
    }
    cout<<ans<<endl;
	return 0;
}


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

long long m,n,l=0,r=-1;
long long a[100005],b[100005];

bool check(long long t){

	//copy
	for(int i=0;i<n;i++){
		b[i] = a[i];
	}
	// cout<<m<<endl;
	long long person = 1;

	//from end to begin ,and check each box
	long long tp = t;

	for(int i=0;i<n;i++){
			if(b[i]){
				tp -= (i+1);
				if(tp - i - 1 > 0){
					while(tp >= 0 && i < n){

						if(tp > b[i]){
							tp -= b[i];

							i++;
						}
						else{
							b[i] -= tp;
							person++;
							i--;
							break;
						}
					}
				}
				else{
					tp = t;
					person++;
					i--;
				}
				if(person > m)return false;
			}
	}
	return person <= m;
}

int main(){
	std::ios::sync_with_stdio(false);
	cin.tie(0);

	cin>>n>>m;
	long long sum = 0;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sum = pow(10,15);

	l = 0 ;
	r = sum;
	long long mid;
	while(l+1<r){
		mid = l + (r-l)/2;
		// cout<<"L"<<l<<"mid"<<mid<<"R"<<r<<endl;
		if(check(mid))r = mid;
		else l = mid;
	}
	if(check(l)){
		cout<<l<<endl;
	}
	else{
		cout<<r<<endl;
	}
}


#include<bits/stdc++.h>
using namespace std;
long long a[100005]= {0};
long long b[100005]= {0};
int main()
{
	ios::sync_with_stdio(false);
	//cin.tie(0);
	long long n,m;
	cin>>n>>m;
	long long t=n*m;
	for (long long i=1; i<=n; i++)
	{
		cin>>a[i];
		t+=a[i];
	}
	long long l=1,r=t;
	while (l<r)
	{
		long long mid=l+(r-l)/2,lo;
		for (int i=1;i<=n;i++)
			if (a[i]!=0)
			{
				lo=i;
				break;
			}
		memcpy(b,a,(n+2)*sizeof(long long));
		for (long long i=1; i<=m; i++)
		{
			long long time=mid-lo,temp=lo,ok=1;
			while (time)
			{
				if (b[temp]==0)
				{
					time--;
					temp++;
				}
				else
				{
					if (time>b[temp])
					{
						time-=b[temp];
						b[temp]=0;
					}
					else
					{
						b[temp]-=time;
						time=0;
					}
				}
				lo=temp;
				for (long long i=lo; i<=n; i++)
				{
					if (b[i]!=0)
					{
						ok=0;
						break;
					}
					if (i==n && b[i]==0) ok=1;
				}
				if (ok==1) break;
			}
			if (ok==1) break;
		}
		for (long long i=lo; i<=n; i++)
		{
			if (b[i]!=0)
			{
				l=mid+1;
				break;
			}
			if (i==n && b[i]==0)
			{
				r=mid;
				break;
			}
		}
	}
	cout<<r;
	return 0;
}


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

long long n,m,a[(int)1e5 + 5],b[(int)1e5+5];

bool check(long long t){
    for(int i=0;i<n;i++){
        b[i] = a[i];
    }
    // printf("\n");
    long long np = 0;

    long long p=t;
    for(int i=n-1;i>=0;i--){
        if(b[i]){
            p -= (i+1);
            if(p <= 0)return 0;
            if(np > m)return 0;

            while(p > 0 && i >= 0){
                if(p > b[i]){
                    // printf("people: %d , nowplace: %d , restlife : %d\n",np,i,p);
                    p -= b[i];
                    i--;
                }
                else{
                    // printf("people: %d , nowplace: %d , restlife : %d\n",np,i,p);
                    b[i] -= p;
                    i++;
                    np++;
                    p = t;
                    break;
                }
            }
        }
    }

    if(np < m){
        return 1;
    }
    else{
        if(np == m){
            if(p == t)return 1;
            else return 0;
        }
        else{
            return 0;
        }
    }
}

int main(){
    ios::sync_with_stdio(false);

    cin>>n>>m;
    for(int i;i<n;i++){
        cin>>a[i];
    }

    long long mid, l = 0,r = 1000000000000;
    while(l + 1 < r){
        mid = l +(r-l)/2 ;
        if(check(mid))r = mid;
        else l = mid;
    }

    if(check(l)){
        cout<<l<<endl;
    }
    else{
        cout<<r<<endl;
    }
    return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
vector<ll> v;
bool canPlace(ll sec) {
    ll temp[n+10];
	for(int i=0;i<n;i++)
        temp[i]=v[i];
    ll rem=m,lsti=0,lstsec=sec;

    for(int i=1;i<=n;i++)
    {
        while(temp[i] && rem)
        {
            lstsec-=i-lsti;
            lstsec=max(lstsec,0ll);
            lsti=i;
            ll removed=min(temp[i],lstsec);
            temp[i]-=removed;
            lstsec-=removed;
            if(lstsec==0 && rem)
                rem--,lstsec=sec,lsti=0;
        }
        if(temp[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	ll best=-1;
    while(s<=e)
    {
        ll mid=(s+e)>>1;
        if(canPlace(mid))
            best=mid,e=mid-1;
        else
            s=mid+1;
    }
    return best;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m; v.resize(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum+=v[i];
	}
	cout << (BS2(1, (1LL<<60))+1);
	return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
vector<ll> v;
bool canPlace(ll s) {
	ll copy[n];
	for(int i=0;i<n;i++) copy[i]=v[i];
    ll rem=m,ind=0,last=s;
    for(int i=0;i<n;i++) {
        while(copy[i] && rem) {
            last=max(last-i-ind, 0LL);
            ind=i;
            ll removed=min(copy[i],last);
            copy[i]-=removed;
            last-=removed;
            if(last==0 && rem)
                rem--,last=s,ind=0;
        }
        if(copy[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	ll best=-1;
    while(s<=e)
    {
        ll mid=(s+e)>>1;
        if(canPlace(mid))
            best=mid,e=mid-1;
        else
            s=mid+1;
    }
    return best;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m; v.resize(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum+=v[i];
	}
	cout << (BS2(1, (1LL<<60))+1);
	return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
int v[100010];
bool canPlace(ll sec) {
    ll temp[n+10];
	for(int i=0;i<=n;i++)
        temp[i]=v[i];
    ll rem=m,lsti=0,lstsec=sec;

    for(int i=1;i<=n;i++)
    {
        while(temp[i] && rem)
        {
            lstsec-=i-lsti;
            lstsec=max(lstsec,0ll);
            lsti=i;
            ll removed=min(temp[i],lstsec);
            temp[i]-=removed;
            lstsec-=removed;
            if(lstsec==0 && rem)
                rem--,lstsec=sec,lsti=0;
        }
        if(temp[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	ll best=-1;
    while(s<=e)
    {
        ll mid=(s+e)>>1;
        if(canPlace(mid))
            best=mid,e=mid-1;
        else
            s=mid+1;
    }
    return best;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m;
	ll sum = 0;
	for(int i=1;i<=n;i++)
        cin>>v[i];
	cout << (BS2(1, (1LL<<60)));
	return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
vector<ll> v;
bool canPlace(ll s) {
	ll copy[n];
	for(int i=0;i<n;i++) copy[i]=v[i];
    ll rem=m,ind=0,last=s;
    for(int i=0;i<n;i++) {
        while(copy[i] && rem) {
            last=max(last-i-ind, 0LL);
            ind=i;
            ll removed=min(copy[i],last);
            copy[i]-=removed;
            last-=removed;
            if(last==0 && rem)
                rem--,last=s,ind=0;
        }
        if(copy[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	while (e > s) {
	ll m = s + (e-s)/2;
	if (canPlace(m)) {
		e = m;
	} else {
		s = m+1;
	}
}
	return s;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m; v.resize(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum+=v[i];
	}
	cout << (BS2(1, (1LL<<60))+1);
	return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
vector<ll> v;
bool canPlace(ll s) {
	ll copy[n];
	for(int i=0;i<n;i++) copy[i]=v[i];
    ll rem=m,ind=0,last=s;
    for(int i=0;i<n;i++) {
        while(copy[i] && rem) {
            last=max(last-i-ind, 0LL);
            ind=i;
            ll removed=min(copy[i],last);
            copy[i]-=removed;
            last-=removed;
            if(last==0 && rem)
                rem--,last=s,ind=0;
        }
        if(copy[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	while (e > s) {
	ll m = s + (e-s)/2;
	if (canPlace(m)) {
		e = m;
	} else {
		s = m+1;
	}
}
	return s;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m; v.resize(n);
	ll sum = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		sum+=v[i];
	}
	cout << (BS2(1, 100)+1);
	return 0;
}


//
//  main.cpp
//  Codeforces396
//
//  Created by Mohamad Ali Itani on 07/02/2017.
//  Copyright © 2017 Mohamad Ali Itani. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

int n,m;
vector<ll> v;
bool canPlace(ll sec) {
    ll temp[n+10];
	for(int i=0;i<=n;i++)
        temp[i]=v[i];
    ll rem=m,lsti=0,lstsec=sec;

    for(int i=1;i<=n;i++)
    {
        while(temp[i] && rem)
        {
            lstsec-=i-lsti;
            lstsec=max(lstsec,0ll);
            lsti=i;
            ll removed=min(temp[i],lstsec);
            temp[i]-=removed;
            lstsec-=removed;
            if(lstsec==0 && rem)
                rem--,lstsec=sec,lsti=0;
        }
        if(temp[i])
            return 0;
    }
    return 1;
}

ll BS2(ll s, ll e) {
	ll best=-1;
    while(s<=e)
    {
        ll mid=(s+e)>>1;
        if(canPlace(mid))
            best=mid,e=mid-1;
        else
            s=mid+1;
    }
    return best;
}
int main() {
	ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
	cin >> n >> m; v.resize(n);
	ll sum = 0;
	for(int i=1;i<=n;i++)
        cin>>v[i];
	cout << (BS2(1, (1LL<<60)));
	return 0;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    for(int i = 1 , now = 0;i <= m;i ++) {
        int ithas = x - i;
        if(now == n + 1) break;
        while(now <= n && ithas > 0) {
            int tmp = min(b[now] , ithas);
            b[now] -= tmp; ithas -= tmp;
            if(!ithas) break;
            else {
                ithas --;
                now ++;
            }
            if(now == n + 1) break;
        }
    }
    for(int i = 1;i <= n;i ++) if(!b[i]) return 0;
    return 1;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    for(int i = 1 , now = 1;i <= m;i ++) {
        int ithas = x - now;
        if(now == n + 1) break;
        while(now <= n && ithas > 0) {
            int tmp = min(b[now] , ithas);
            b[now] -= tmp; ithas -= tmp;
            if(!ithas) break;
            else {
                ithas --;
                now ++;
            }
            if(now == n + 1) break;
        }
    }
    for(int i = 1;i <= n;i ++) if(!b[i]) return 0;
    return 1;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    for(int i = 1 , now = 0;i <= m;i ++) {
        int ithas = x - i;
        if(now == n) break;
        while(now <= n && ithas > 0) {
            int tmp = min(b[now] , ithas);
            b[now] -= tmp; ithas -= tmp;
            if(!ithas) break;
            else {
                ithas --;
                now ++;
            }
            if(now == n) break;
        }
    }
    for(int i = 1;i <= n;i ++) if(!b[i]) return 0;
    return 1;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    int now = 1;
    for(int i = 1;i <= n - 1;i ++) {
        int it = b[i] / m, b[i + 1] += b[i] % m;
        now += it + 1;
    }
    now += (b[n] - 1) / m + 1;
    if(now <= t) return 1;return 0;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    for(int i = 1 , now = 1;i <= m;i ++) {
        int ithas = x - now;
        if(now == n + 1) break;
        while(now <= n && ithas > 0) {
            int tmp = min(b[now] , ithas);
            b[now] -= tmp; ithas -= tmp;
            if(!ithas) break;
            else {
                ithas --;
                now ++;
            }
            if(now == n + 1) break;
        }
    }
    for(int i = 1;i <= n;i ++) if(b[i]) return 0;
    return 1;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    for(int i = 1 , now = 1;i <= m;i ++) {
        int ithas = x - now;
        if(now == n) break;
        while(now <= n && ithas > 0) {
            int tmp = min(b[now] , ithas);
            b[now] -= tmp; ithas -= tmp;
            if(!ithas) break;
            else {
                ithas --;
                now ++;
            }
            if(now == n) break;
        }
    }
    for(int i = 1;i <= n;i ++) if(!b[i]) return 0;
    return 1;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

bool pd(int x) {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    int now = 1;
    for(int i = 1;i <= n - 1;i ++) {
        int it = b[i] / m; b[i + 1] += b[i] % m;
        now += it + 1;
    }
    now += (b[n] - 1) / m + 1;
    if(now <= t) return 1;return 0;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    int l = 0 ,r = 1e18;
    while(l <= r) {
        int mid = (l + r) >> 1;
        if(pd(mid)) {
            ans = mid; r = mid -1;
        }
        else l = mid + 1;
    }
    cout<<ans<<endl;
}


#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;

#define int long long

const int N = 1000005;
const int M = N;

int a[N] , n , m , t , b[N];

int getans() {
    for(int i = 1;i <= n;i ++) b[i] = a[i];
    int now = 1;
    for(int i = 1;i <= n - 1;i ++) {
        int it = b[i] / m; b[i + 1] += b[i] % m;
        now += it + 1;
    }
    now += (b[n] - 1) / m + 1;
    return now;
}

signed main() {
    int ans = 0;
    scanf("%lld%lld",&n,&m);
    for(int i = 1;i <= n;i ++) scanf("%lld",&a[i]);
    while(!a[n] && n) n --;
    if(!n) {
        puts("0");
        return 0;
    }
    ans = getans();
    cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, m;
ll a[maxn];
ll ans, sum;

bool Check(ll x){
	int pos = n;
	ll tmp = x;
	ll b[maxn] = {0};
	for(int i = 1; i <= m; i++){
		tmp = x - pos;
		while(pos >= 1 && tmp > 0)
		{
			ll t = a[pos] - b[pos];
			if(t > tmp){
				b[pos] += tmp;
				break;
			}
			else if(t <= tmp){
				tmp -= t;
				b[pos] = a[pos];
				pos--;
				while(pos >= 1 && a[pos] == 0){
					pos--;
				}
			}
		}
	}
	if(pos < 1)
		return 1;
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m){
		sum = 0;
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			sum += a[i];
		}
		for(int i = n; i >= 1; i--)
			if(a[i] == 0)
				n--;
			else
				break;
		sum += n;
		ll s = 0, e = sum;
		while(s < e){
			ll mid = (s + e) / 2;
			if(Check(mid))
				e = mid;
			else
				s = mid + 1;
		}
		if(Check(s))
			cout << s << endl;
		else
			cout << e << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, m;
ll a[maxn];
ll ans, sum;

bool Check(int x){
	int pos = n, tmp = x;
	int b[maxn] = {0};
	for(int i = 1; i <= m; i++){
		tmp = x - pos;
		while(pos >= 1 && tmp > 0)
		{
			ll t = a[pos] - b[pos];
			if(t > tmp){
				b[pos] += tmp;
				break;
			}
			else if(t <= tmp){
				tmp -= t;
				b[pos] = a[pos];
				pos--;
				while(pos >= 1 && a[pos] == 0){
					pos--;
				}
			}
		}
	}
	if(pos < 1)
		return 1;
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m){
		sum = 0;
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			sum += a[i];
		}
		for(int i = n; i >= 1; i--)
			if(a[i] == 0)
				n--;
			else
				break;
		sum += n;
		ll s = 0, e = sum;
		while(s < e){
			ll mid = (s + e) / 2;
			if(Check(mid))
				e = mid;
			else
				s = mid + 1;
		}
		if(Check(s))
			cout << s << endl;
		else
			cout << e << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, m;
ll a[maxn], a_t[maxn];
ll ans, tmp;

int main()
{
	ios::sync_with_stdio(false);
	while(cin >> n >> m){
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			a_t[i] = a[i];
		}
		ans = 0;
		tmp = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] <= 0){
				if(a_t[i] > 0)
				{
					ans += tmp + 1;
					tmp = 0;
				}
				else
					tmp++;
				a[i + 1] += a[i];
			}
			else if(a[i] >= m){
				ans += tmp;
				tmp = 0;
				ans++;
				if(a[i] % m == 0){
					ans += a[i] / m;
				}
				else{
					ans += a[i] / m + 1;
					a[i + 1] -= m - a[i] % m;
				}
			}
			else if(a[i] < m){
				ans += tmp;
				tmp = 0;
				ans += 2;
				a[i + 1] -= m - a[i];
			}
			else{
				for(int j = 0; j < 10000; j++)
					cout << "1" << endl;
			}
//			cout << ans << " " << tmp << endl;
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, m;
ll a[maxn], a_t[maxn];
ll ans, tmp;

int main()
{
	while(scanf("%d%d", &n, &m) != EOF){
		for(int i = 1; i <= n; i++){
			scanf("%d", &a[i]);
			a_t[i] = a[i];
		}
		ans = 0;
		tmp = 0;
		for(int i = 1; i <= n; i++){
			if(a[i] <= 0){
				if(a_t[i] > 0)
				{
					ans += tmp + 1;
					tmp = 0;
				}
				else
					tmp++;
				a[i + 1] += a[i];
			}
			else if(a[i] >= m){
				ans += tmp;
				tmp = 0;
				ans++;
				if(a[i] % m == 0){
					ans += a[i] / m;
				}
				else{
					ans += a[i] / m + 1;
					a[i + 1] -= m - a[i] % m;
				}
			}
			else if(a[i] < m){
				ans += tmp;
				tmp = 0;
				ans += 2;
				a[i + 1] -= m - a[i];
			}
			else{
				for(int j = 0; j < 10000; j++)
					cout << "1" << endl;
			}
//			cout << ans << " " << tmp << endl;
		}
		cout << ans << endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long ll;
const int maxn = 1e5 + 5;
int n, m;
ll a[maxn];
ll ans, sum;

bool Check(int x){
	int pos = n, tmp = x;
	ll b[maxn] = {0};
	for(int i = 1; i <= m; i++){
		tmp = x - pos;
		while(pos >= 1 && tmp > 0)
		{
			ll t = a[pos] - b[pos];
			if(t > tmp){
				b[pos] += tmp;
				break;
			}
			else if(t <= tmp){
				tmp -= t;
				b[pos] = a[pos];
				pos--;
				while(pos >= 1 && a[pos] == 0){
					pos--;
				}
			}
		}
	}
	if(pos < 1)
		return 1;
	return 0;
}

int main(){
	ios::sync_with_stdio(false);
	while(cin >> n >> m){
		sum = 0;
		for(int i = 1; i <= n; i++){
			cin >> a[i];
			sum += a[i];
		}
		for(int i = n; i >= 1; i--)
			if(a[i] == 0)
				n--;
			else
				break;
		sum += n;
		ll s = 0, e = sum;
		while(s < e){
			ll mid = (s + e) / 2;
			if(Check(mid))
				e = mid;
			else
				s = mid + 1;
		}
		if(Check(s))
			cout << s << endl;
		else
			cout << e << endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, m;
int a[N];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    long long t = 0;
    while (a[n] == 0 && n > 0)
        --n;
    int q = m;
    ++t;
    for (int i = 1; i <= n; ++i)
    {
        if (q <= a[i])
        {
            ++t;
            a[i] -= q;
            q = m;
            t += (a[i] / m);
            q = m - (a[i] % m);
            if (i < n)
            {
                ++t;
            }
            else
            {
                if (a[i] % m != 0)
                    ++t;
            }
        }
        else
        {
            ++t;
            q = q - a[i];
        }
    }
    printf("%lld\n", t);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;
const long long INF = 100005000000009;

int n, m;
int a[N];
int aa[N];

bool stg(long long t)
{
    for (int i = 1; i <= n; ++i)
        a[i] = aa[i];
    int j = n;
    for (int i = 0; i < m; ++i)
    {
        while (!a[j] && j > 0)
            --j;
        long long tt = t;
        tt -= j;
        while (1)
        {
            if (!j)
                return true;
            if (tt >= a[j])
            {
                tt -= a[j];
                --j;
            }
            else
            {
                a[j] -= tt;
                break;
            }
        }
    }
    return false;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        aa[i] = a[i];
    long long l = 0, r = INF;
    long long ans;
    while (l <= r)
    {
        long long m = l + (r - l) / 2;
        if (stg(m))
        {
            ans = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;
const long long INF = 100005000000009;

int n, m;
int a[N];
int aa[N];

bool stg(long long t)
{
    for (int i = 1; i <= n; ++i)
        a[i] = aa[i];
    int j = n;
    for (int i = 0; i < m; ++i)
    {
        while (!a[j] && j > 0)
            --j;
        long long tt = t;
        tt -= j;
        while (1)
        {
            if (!j)
                return true;
            if (tt >= a[j])
            {
                tt -= a[j];
                --j;
            }
            else
            {
                a[j] -= tt;
                break;
            }
        }
    }
    return false;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        aa[i] = a[i];
    long long l = 0, r = INF;
    long long ans;
    while (l <= r)
    {
        long long m = (l + r) / 2;
        if (stg(m))
        {
            ans = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;
const long long INF = 100005000000009;

int n, m;
int a[N];
int aa[N];

bool stg(long long t)
{
    for (int i = 1; i <= n; ++i)
        a[i] = aa[i];
    int j = n;
    for (int i = 0; i < m; ++i)
    {
        while (!a[j] && j > 0)
            --j;
        long long tt = t;
        tt -= j;
        if (tt < 0)
            continue;
        while (1)
        {
            if (!j)
                return true;
            if (tt >= a[j])
            {
                tt -= a[j];
                --j;
            }
            else
            {
                a[j] -= tt;
                break;
            }
        }
    }
    return false;
}

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= n; ++i)
        aa[i] = a[i];
    long long l = 0, r = INF;
    long long ans;
    while (l <= r)
    {
        long long m = l + (r - l) / 2;
        if (stg(m))
        {
            ans = m;
            r = m - 1;
        }
        else
            l = m + 1;
    }
    printf("%lld\n", ans);
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 100005;

int n, m;
int a[N];

int main()
{
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    long long t = 0;
    while (a[n] == 0 && n > 0)
        --n;
    int q0 = m, q1 = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (!q1)
        {
            ++t;
            swap(q0, q1);
        }
        if (!a[i])
        {
            ++t;
            continue;
        }
        if (q1 <= a[i])
        {
            ++t;
            a[i] -= q1;
            q1 += q0;
            q0 = 0;
            t += (a[i] / q1);
            q0 = (a[i] % m);
            q1 = m - (a[i] % m);
            if (i < n)
            {
                ++t;
            }
            else
            {
                if (a[i] % m != 0)
                    ++t;
            }
        }
        else
        {
            ++t;
            q1 = q1 - a[i];
            q0 = m - q1;
        }
    }
    printf("%lld\n", t);
    return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vi arr){
        int i = n-1;
        f(j, m){
            while(i>=0 and !arr[i]) --i;
            ll remain = time-(i+1);
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], arr[i] = 0, --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        while(i>=0 and !arr[i]) --i;
        return i==-1;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vi arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e14, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vi arr){
        f(j, m){
            int i = n-1;
            while(i>=0 and !arr[i]) --i;
            ll remain = time-(i+1);
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], arr[i] = 0, --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        f(i, n) if(arr[i]) return false;
        return true;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vi arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e14, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vl arr){
        int i;
        f(j, m){
            i = n-1;
            while(i>=0 and !arr[i]) --i;
            ll remain = time-(i+1);
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], arr[i] = 0, --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        while(i>=0 and !arr[i]) --i;
        return i==-1;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vl arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e18, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vl arr){
        f(j, m){
            int i = n-1;
            while(i>=0 and !arr[i]) --i;
            ll remain = time-(i+1);
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], arr[i] = 0, --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        f(i, n) if(arr[i]) return false;
        return true;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vl arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e14, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vl arr){
        int i = n-1;
        while(i>=0 and !arr[i]) --i;
        time -= (i+1);
        f(j, m){
            ll remain = time;
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        while(i>=0 and !arr[i]) --i;
        return i==-1;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vl arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 100, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vi arr){
        int i = n-1;
        f(j, m){
            while(i>=0 and !arr[i]) --i;
            ll remain = time-(i+1);
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], arr[i] = 0, --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        while(i>=0 and !arr[i]) --i;
        return i==-1;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vi arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e18, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author HARSHAD
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ld PI = 3.14159265358979323846;

#define f(i,n) for(int i=0;i<n;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)

template <typename T> using ordered_set =  tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

class CGukiZHatesBoxes {
public:
    ll n, m;
    bool ok(ll time, vl arr){
        int i = n-1;
        while(i>=0 and !arr[i]) --i;
        time -= (i+1);
        f(j, m){
            ll remain = time;
            while(i>=0 and remain>0){
                if(arr[i]<=remain) remain -= arr[i], --i;
                else arr[i] -= remain, remain = 0;
            }
        }
        while(i>=0 and !arr[i]) --i;
        return i==-1;
    }
	void solve(std::istream& in, std::ostream& out) {
		in>>n>>m;
        vl arr(n);
        f(i, n) in>>arr[i];
        ll low = 0, high = 1e18, res = -1;
        while(low<=high){
            ll mid = (low+high)>>1;
            if(ok(mid, arr)){
                res = mid;
                high = mid - 1;
            }
            else low = mid + 1;
        }
		out<<res;
	}
};

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	CGukiZHatesBoxes solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

vector<long long> arr,aux;
long long piles, students;

int main()
{
    IO;
    cin >> piles >> students;
    arr.resize(piles + 5);
    aux.resize(piles + 5);
    for(int i = 0; i < piles; i++)
    {
        cin >> arr[i];
    }
    long long st = 0, en = 1e20, mid;
    bool flag;
    while (st < en)
    {
        mid = st + (en - st) / 2;
        aux = arr;
        flag = true;
        long long lastNonZero = piles - 1;
        for(int i = 0; i < students; i++)
        {
            while (lastNonZero >= 0 && aux[lastNonZero] == 0)
                lastNonZero--;
            long long minimumNeededTime = mid - (lastNonZero + 1);
            if(minimumNeededTime <= 0)
            {
                flag = false;
                break;
            }
            while (lastNonZero >= 0 && minimumNeededTime >= aux[lastNonZero])
            {
                minimumNeededTime -= aux[lastNonZero];
                aux[lastNonZero--] = 0;
            }
            if(lastNonZero >= 0)
                aux[lastNonZero] -= minimumNeededTime;
        }
        if(flag)
        {
            for(int i = 0; i < piles; i++)
            {
                if(aux[i] > 0)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            en = mid;
        else
            st = mid + 1;
    }
    cout << st;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

vector<long long> arr,aux;
long long piles, students;

int main()
{
    IO;
    cin >> piles >> students;
    arr.resize(piles + 5);
    aux.resize(piles + 5);
    for(int i = 0; i < piles; i++)
    {
        cin >> arr[i];
    }
    long long st = 0, en = 1e9, mid;
    bool flag;
    while (st < en)
    {
        mid = st + (en - st) / 2;
        aux = arr;
        flag = true;
        long long lastNonZero = piles - 1;
        for(int i = 0; i < students; i++)
        {
            while (lastNonZero >= 0 && aux[lastNonZero] == 0)
                lastNonZero--;
            long long minimumNeededTime = mid - (lastNonZero + 1);
            if(minimumNeededTime <= 0)
            {
                flag = false;
                break;
            }
            while (lastNonZero >= 0 && minimumNeededTime >= aux[lastNonZero])
            {
                minimumNeededTime -= aux[lastNonZero];
                aux[lastNonZero--] = 0;
            }
        }
        if(!flag)
        {
            for(int i = 0; i < piles; i++)
            {
                if(aux[i] > 0)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            en = mid;
        else
            st = mid + 1;
    }
    cout << st;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

vector<long long> arr,aux;
long long piles, students;

int main()
{
    IO;
    cin >> piles >> students;
    arr.resize(piles + 1);
    aux.resize(piles + 1);
    for(int i = 1; i <= piles; i++)
    {
        cin >> arr[i];
    }
    long long st = 1, en = 1e9, mid;
    bool flag;
    while (st < en)
    {
        mid = st + (en - st) / 2;
        aux = arr;
        flag = true;
        long long lastNonZero = piles;
        for(int i = 1; i <= students; i++)
        {
            while (lastNonZero >= 1 && aux[lastNonZero] == 0)
                lastNonZero--;
            long long minimumNeededTime = mid - (lastNonZero + 1);
            if(minimumNeededTime <= 0)
            {
                flag = false;
                break;
            }
            while (lastNonZero >= 1 && minimumNeededTime >= aux[lastNonZero])
            {
                minimumNeededTime -= aux[lastNonZero];
                aux[lastNonZero--] = 0;
            }
        }
        if(!flag)
        {
            for(int i = 1; i <= piles; i++)
            {
                if(aux[i] > 0)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            en = mid;
        else
            st = mid + 1;
    }
    cout << st;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

vector<long long> arr,aux;
long long piles, students;

int main()
{
    IO;
    cin >> piles >> students;
    arr.resize(piles + 5);
    aux.resize(piles + 5);
    for(int i = 0; i < piles; i++)
    {
        cin >> arr[i];
    }
    long long st = 0, en = 1e9, mid;
    bool flag;
    while (st < en)
    {
        mid = (st + en) / 2;
        aux = arr;
        flag = true;
        long long lastNonZero = piles - 1;
        for(int i = 0; i < students; i++)
        {
            while (lastNonZero >= 0 && aux[lastNonZero] == 0)
                lastNonZero--;
            long long minimumNeededTime = mid - (lastNonZero + 1);
            if(minimumNeededTime <= 0)
            {
                flag = false;
                break;
            }
            while (lastNonZero >= 0 && minimumNeededTime >= aux[lastNonZero])
            {
                minimumNeededTime -= aux[lastNonZero];
                aux[lastNonZero--] = 0;
            }
            if(lastNonZero >= 0)
                aux[lastNonZero] -= minimumNeededTime;
        }
        if(flag)
        {
            for(int i = 0; i < piles; i++)
            {
                if(aux[i] > 0)
                {
                    flag = false;
                    break;
                }
            }
        }
        if(flag)
            en = mid;
        else
            st = mid + 1;
    }
    cout << st;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define pll pair<ll,ll>

// Modulur Addition
ll sum_mod(ll a, ll b)
{
    return (a + b) % mod;
}

// Modulur Subtraction
ll subtract_mod(ll a, ll b)
{
    return (a % mod - b % mod + mod) % mod;
}

// Modulur Multiplication
ll multiply_mod(ll a, ll b)
{
    return (a % mod * b % mod) % mod;
}

// Inverse Modulo
ll modInverse(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

// Modulur Division
ll divide_mod(ll a, ll b)
{
    return (a * modInverse(b, mod - 2)) % mod;
}

// GCD function
ll gcd(ll a, ll b)
{
    while(b) swap(a %= b, b);
    return a;
}

bool check(vector<ll> nums, ll m, ll t)
{
    for(ll i = 1;i <= m;++i)
    {
        ll k = t;
        for(ll j = 0;j < nums.size();++j)
        {
            k -= 1;
            if(k >= nums[j]) k -= nums[j], nums[j] = 0;
            else nums[j] -= k, k = 0;
            if(k == 0) break;
        }
        if(count(nums.begin(), nums.end(), 0) == nums.size()) return true;
    }
    return false;
}

// main function
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    ll r = 0;
    for(ll i = 0;i < n;++i) cin >> nums[i], r += nums[i];
    r += n;
    ll l = 0;
    while(l < r)
    {
        ll md = l +(r - l) / 2;
        if(check(nums, m, md)) r = md;
        else l = md+1;
    }
    cout << l << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define pll pair<ll,ll>

// Modulur Addition
ll sum_mod(ll a, ll b)
{
    return (a + b) % mod;
}

// Modulur Subtraction
ll subtract_mod(ll a, ll b)
{
    return (a % mod - b % mod + mod) % mod;
}

// Modulur Multiplication
ll multiply_mod(ll a, ll b)
{
    return (a % mod * b % mod) % mod;
}

// Inverse Modulo
ll modInverse(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

// Modulur Division
ll divide_mod(ll a, ll b)
{
    return (a * modInverse(b, mod - 2)) % mod;
}

// GCD function
ll gcd(ll a, ll b)
{
    while(b) swap(a %= b, b);
    return a;
}

bool check(vector<ll> nums, ll m, ll t)
{
    ll j = 0;
    for(ll i = 1;i <= m;++i)
    {
        ll k = t;
        k -= (j+1);
        while(k > 0 && j < nums.size())
        {
            if(nums[j] <= k) k -= nums[j], nums[j] = 0, j++, k--;
            else nums[j] -= k, k = 0;
        }
        while(j < nums.size() && nums[j] == 0) j++;
        if(j == nums.size()) return true;
    }
    return false;
}

// main function
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    ll r = 0;
    for(ll i = 0;i < n;++i) cin >> nums[i], r += nums[i];
    r += n;
    ll l = 0;
    while(l < r)
    {
        ll md = l +(r - l) / 2;
        if(check(nums, m, md)) r = md;
        else l = md+1;
    }
    cout << l << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define pll pair<ll,ll>

// Modulur Addition
ll sum_mod(ll a, ll b)
{
    return (a + b) % mod;
}

// Modulur Subtraction
ll subtract_mod(ll a, ll b)
{
    return (a % mod - b % mod + mod) % mod;
}

// Modulur Multiplication
ll multiply_mod(ll a, ll b)
{
    return (a % mod * b % mod) % mod;
}

// Inverse Modulo
ll modInverse(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

// Modulur Division
ll divide_mod(ll a, ll b)
{
    return (a * modInverse(b, mod - 2)) % mod;
}

// GCD function
ll gcd(ll a, ll b)
{
    while(b) swap(a %= b, b);
    return a;
}

bool check(vector<ll> nums, ll m, ll t)
{
    ll j = 0;
    for(ll i = 1;i <= m;++i)
    {
        ll k = t;
        k -= (j+1);
        while(k && j < nums.size())
        {
            if(nums[j] <= k) k -= nums[j], nums[j] = 0, j++, k--;
            else nums[j] -= k, k = 0;
        }
        while(j < nums.size() && nums[j] == 0) j++;
        if(j == nums.size()) return true;
    }
    return false;
}

// main function
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    ll r = 0;
    for(ll i = 0;i < n;++i) cin >> nums[i], r += nums[i];
    r += n;
    ll l = 0;
    while(l < r)
    {
        ll md = l +(r - l) / 2;
        if(check(nums, m, md)) r = md;
        else l = md+1;
    }
    check(nums, m, l-1) ? cout << l-1 << endl : cout << l << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define pll pair<ll,ll>

// Modulur Addition
ll sum_mod(ll a, ll b)
{
    return (a + b) % mod;
}

// Modulur Subtraction
ll subtract_mod(ll a, ll b)
{
    return (a % mod - b % mod + mod) % mod;
}

// Modulur Multiplication
ll multiply_mod(ll a, ll b)
{
    return (a % mod * b % mod) % mod;
}

// Inverse Modulo
ll modInverse(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

// Modulur Division
ll divide_mod(ll a, ll b)
{
    return (a * modInverse(b, mod - 2)) % mod;
}

// GCD function
ll gcd(ll a, ll b)
{
    while(b) swap(a %= b, b);
    return a;
}

bool check(vector<ll> nums, ll m, ll t)
{
    ll j = 0;
    for(ll i = 1;i <= m;++i)
    {
        ll k = t;
        k -= (j+1);
        while(k && j < nums.size())
        {
            if(nums[j] <= k) k -= nums[j], nums[j] = 0, j++, k--;
            else nums[j] -= k, k = 0;
        }
        while(j < nums.size() && nums[j] == 0) j++;
        if(j == nums.size()) return true;
    }
    return false;
}

// main function
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    ll r = 0;
    for(ll i = 0;i < n;++i) cin >> nums[i], r += nums[i];
    r += n;
    ll l = 0;
    while(l < r)
    {
        ll md = l +(r - l) / 2;
        if(check(nums, m, md)) r = md;
        else l = md+1;
    }
    cout << l << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define mod 1000000007
#define pb push_back
#define pll pair<ll,ll>

// Modulur Addition
ll sum_mod(ll a, ll b)
{
    return (a + b) % mod;
}

// Modulur Subtraction
ll subtract_mod(ll a, ll b)
{
    return (a % mod - b % mod + mod) % mod;
}

// Modulur Multiplication
ll multiply_mod(ll a, ll b)
{
    return (a % mod * b % mod) % mod;
}

// Inverse Modulo
ll modInverse(ll x, ll y)
{
    ll res = 1;
    x = x % mod;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % mod;
        y = y >> 1;
        x = (x * x) % mod;
    }
    return res;
}

// Modulur Division
ll divide_mod(ll a, ll b)
{
    return (a * modInverse(b, mod - 2)) % mod;
}

// GCD function
ll gcd(ll a, ll b)
{
    while(b) swap(a %= b, b);
    return a;
}

bool check(vector<ll> nums, ll m, ll t)
{
    ll j = 0;
    for(ll i = 1;i <= m;++i)
    {
        ll k = t;
        k -= (j+1);
        while(k && j < nums.size())
        {
            if(nums[j] <= k) k -= nums[j], nums[j] = 0, j++, k--;
            else nums[j] -= k, k = 0;
        }
        while(j < nums.size() && nums[j] == 0) j++;
        if(j == nums.size()) return true;
    }
    return false;
}

// main function
int main()
{
    ll n, m;
    cin >> n >> m;
    vector<ll> nums(n);
    ll r = 0;
    for(ll i = 0;i < n;++i) cin >> nums[i], r += nums[i];
    r += n;
    ll l = 0;
    while(l < r-1)
    {
        ll md = l +(r - l) / 2;
        if(check(nums, m, md)) r = md;
        else l = md;
    }
    cout << r << endl;
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000200000;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) return 1;
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            for (;!b[j]&&j;j--);
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t>=S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;j--)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (dis+p==mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
int l,r,mid,S,t,p,dis;

inline  bool    Check(int mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p==mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000200000;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) return 1;
        dis=0;p=0;
        for (;j;)
        {
        	if (dis+p>=mid) break;
            if (b[j])
            {
                if (!dis) dis=j;
                if (b[j]+dis+p<=mid)
                {
                	p+=b[j];
                	b[j]=0;
				}
				else
				{
					p=mid-dis;
					b[j]-=mid-dis-p;
					break;
				}
            }
            for (;!b[j]&&j;j--);
        }
        t+=p;
    }
    return t>=S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (register i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=1000200000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
int l,r,mid,S,t,p,dis;

inline  bool    Check(int mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000200000;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) break;
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            for (;!b[j];j--);
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=1000200000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
int l,r,mid,S,t,p,dis;

inline  bool    Check(int mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;j--)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (dis+p==mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000200000;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (register int i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=1000200000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) return 1;
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                if (b[j]+dis+p<=mid)
                {
                	p+=b[j];
                	b[j]=0;
				}
				else
				{
					p=mid-dis;
					b[j]-=mid-dis-p;
					break;
				}
            }
            for (;!b[j]&&j;j--);
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t>=S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (!b[j]) j--;
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=1000200000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (j=n;j;j--)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (dis+p==mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=2000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) return 1;
        dis=0;p=0;
        for (;j;)
        {
        	if (dis+p>=mid) break;
            if (b[j])
            {
                if (!dis) dis=j;
                if (b[j]+dis+p<=mid)
                {
                	p+=b[j];
                	b[j]=0;
				}
				else
				{
					b[j]-=mid-dis-p;
					p=mid-dis;
					break;
				}
            }
            for (;!b[j]&&j;j--);
        }
        t+=p;
    }
    return t>=S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


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

int i,j,k,n,m,a[N],b[N];
int l,r,mid,S,t,p,dis;

inline  bool    Check(int mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    for (i=1;i<=m;i++) if (t<S)
    {
        dis=0;p=0;
        for (;j;j--)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                for (;b[j]&&dis+p<mid;b[j]--) p++;
            }
            if (dis+p==mid) break;
        }
        t+=p;
    }
    return t==S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=a[i];
    }
    l=0;r=1000200000;
    for (;l<=r;)
    {
        mid=(l+r)/2;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%d",l);
}


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

int i,j,k,n,m,a[N],b[N];
long long l,r,mid,S,t,p,dis;

inline  bool    Check(long long mid)
{
    for (i=1;i<=n;i++) b[i]=a[i];
    t=0;
    j=n;
    for (i=1;i<=m;i++)
    {
    	if (t>=S) return 1;
        dis=0;p=0;
        for (;j;)
        {
            if (b[j])
            {
                if (!dis) dis=j;
                if (b[j]+dis+p<=mid)
                {
                	p+=b[j];
                	b[j]=0;
				}
				else
				{
					b[j]-=mid-dis-p;
					break;
				}
            }
            for (;!b[j]&&j;j--);
            if (dis+p>=mid) break;
        }
        t+=p;
    }
    return t>=S;
}

int main()
{
    scanf("%d%d",&n,&m);
    for (i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
        S+=(long long)a[i];
    }
    l=0;r=20000000000000000ll;
    for (;l<=r;)
    {
        mid=(l+r)>>1;
        if (Check(mid)) r=mid-1;
            else l=mid+1;
    }
    printf("%I64d",l);
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 1e5 + 1;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

inline int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;
                cerr << "in if : " << t << " " << j << endl;

            }
            else{
                j++;
                t++;
                cerr << "in else : " << t << " " << j << endl;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    //n -= 1;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = 2 * m;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cerr << l << " " << r << endl;
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 2e5;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;

            }
            else{
                j++;
                t++;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 2e5;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                //if(ans == 3) cerr << "in if : " << t << t + min(ans - t , tmp[j]) << endl;
                t += min((long long)(ans - t) , (long long)tmp[j]);
                tmp[j] -= min(ans - t , tmp[j]);
                //t += min((long long)(ans - t) , (long long)tmp[j]);
                            }
            else{
                j++;
                t++;
                //if(ans == 3) cerr << "in else : " << t << " " << j << endl;
            }
            //if(ans == 3) cerr << m << " : " << t << " " << j << endl;
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cerr << l << " " << r << endl;
    cout << l;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 2e5;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;
                cerr << "in if : " << t << " " << j << endl;

            }
            else{
                j++;
                t++;
                cerr << "in else : " << t << " " << j << endl;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    //n -= 1;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cerr << l << " " << r << endl;
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 1e5 + 10;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

inline int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;

            }
            else{
                j++;
                t++;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = 1e18;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 1e5 + 10;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

inline int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;

            }
            else{
                j++;
                t++;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 2e5;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

inline int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                int anss = min(ans - t , tmp[j]);
                t += anss;
                tmp[j] -= anss;

            }
            else{
                j++;
                t++;
            }
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cout << r;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define int long long
#define F first
#define S second
//#define endl '\n'
#define pb push_back
#define pf push_front
#define mk make_pair
#define pii pair<int,int>
#define vpii vector< pair<int,int> >
#define zr 0ll
#define piii pair<int , pii >
#define sort(a) sort(a.begin(), a.end())
//***************************************************
const int N = 2e5;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;

int a[N], tmp[N], n, m;;

int32_t isok(int ans){
    for(int i = 0 ; i < n ; i++) tmp[i] = a[i];
    int j = 0, t = 0;
    for(int i = 0 ; i < m ; i++){
        t = j + 1;
        //if(ans == 3) cerr << t  << " : " << endl;
        while(t < ans && j < n){
            if(tmp[j] != 0){
                if(ans == 3) cerr << "in if : " << t << t + min(ans - t , tmp[j]) << endl;
                t += min((long long)(ans - t) , (long long)tmp[j]);
                tmp[j] -= min(ans - t , tmp[j]);
                //t += min((long long)(ans - t) , (long long)tmp[j]);
                            }
            else{
                j++;
                t++;
                if(ans == 3) cerr << "in else : " << t << " " << j << endl;
            }
            if(ans == 3) cerr << m << " : " << t << " " << j << endl;
        }
    }
    bool flag = true;
    for(int i = 0 ; i < n ; i++) if(tmp[i] != 0) flag = false;
    return flag;

}

int32_t main(){
    cin >> n >> m;
    for(int i = 0 ; i < n ; i++) cin >> a[i];
    int l = 0, r = INF;
    while(r - l > 1){
        int md = (l + r) / 2;
        if(isok(md)) r = md;
        else l = md;
    }
    cerr << l << " " << r << endl;
    cout << r;
    return 0;
}


#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
using namespace std;

const int maxN = 1e5 + 5;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int n, m, i, j, h[maxN], a[maxN], reach, T, temp;
long long int l, r, mid;

bool isVal(int k){
	for (i = 0; i < n; i++){
		a[i] = h[i];
	}
	reach = 0;
	for (i = 0; i < m; i++){
		T = k - reach - 1;
		while (T && reach != n){
			if (a[reach] == 0){
				reach += 1;
				T -= 1;
				continue;
			}
			temp = min(a[reach], T);
			a[reach] -= temp;
			T -= temp;
		}
	}
	while (reach < n && a[reach] == 0){
		reach += 1;
	}
	return (reach == n);
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> m;
	for (i = 0; i < n; i++){
		cin >> h[i];
	}
	l = 0;
	r = INF;
	while (r - l > 1){
		mid = (l + r) / 2;
		if (isVal(mid)){
			r = mid;
		}
		else{
			l = mid;
		}
	}
	cout << r << endl;
	return 0;
}


mod cp {
    use std::io::prelude::*;
    pub fn stdin_to_string() -> String {
        let mut content = String::new();
        let stdin = std::io::stdin();
        let mut rd = stdin.lock();
        rd.read_to_string(&mut content).unwrap();
        return content;
    }

    pub struct Parser<'a> {
        tokens: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Parser<'a> {
        pub fn new(text: &'a str) -> Self {
            Self {
                tokens: text.split_whitespace(),
            }
        }

        pub fn read_or_eof<T: std::str::FromStr>(&mut self) -> Option<T> {
            self.next().map(|s| match s.parse() {
                Ok(x) => x,
                Err(_) => panic!("cannot parse {:?}", s),
            })
        }

        pub fn read<T: std::str::FromStr>(&mut self) -> T {
            self.read_or_eof::<T>().expect("unexpected end-of-file")
        }
    }

    impl<'a> Iterator for Parser<'a> {
        type Item = &'a str;
        fn next(&mut self) -> Option<&'a str> {
            self.tokens.next()
        }
    }

    #[macro_export]
    macro_rules! take {
        ($p: expr, $n: expr) => {
            $p.by_ref().take($n).map(|x| x.parse().unwrap())
        };
        ($p: expr, $n: expr, $t: ty) => {
            $p.by_ref().take($n).map(|x| x.parse::<$t>().unwrap())
        };
    }

    #[macro_export]
    macro_rules! take_all {
        ($p: expr) => {
            $p.by_ref().map(|x| x.parse().unwrap())
        };
        ($p: expr, $t: ty) => {
            $p.by_ref().map(|x| x.parse::<$t>().unwrap())
        };
    }
}

use cp::*;

fn main() {
    let content = stdin_to_string();
    let mut inp = Parser::new(&content);
    let n: usize = inp.read();
    let a: Vec<i64> = take!(inp, n).collect();
    use std::convert::TryFrom;
    let nn = i64::try_from(n).unwrap();

    if n == 1 {
        println!("1 1");
        println!("0");
        println!("1 1");
        println!("0");
        println!("1 1");
        println!("{}", -a[0]);
        return;
    }

    println!("1 {}", n-1);
    let out = a.iter()
        .take(n-1)
        .cloned()
        .map(|x| format!("{}", (-x % nn) * (nn - 1) * (nn - 1)))
        .collect::<Vec<_>>()
        .join(" ");
    println!("{}", out);

    println!("1 {}", n);
    let out = a.iter()
        .take(n-1)
        .cloned()
        .map(|x| format!("{}", (-x % nn) * (2 - nn) * nn + (x % nn - x)))
        .chain(std::iter::once("0".to_owned()))
        .collect::<Vec<_>>()
        .join(" ");
    println!("{}", out);

    println!("{} {}", n, n);
    println!("{}", -a[n-1]);
}


#![allow(dead_code)]
#![allow(unused)]

#![allow(unused_imports)]
use std::collections::{HashSet, HashMap};
use std::cmp::{min,max,Reverse};
use std::io::{self, prelude::*};
use std::str;

struct Scanner<R> {
    reader: R,
    buf_str: Vec<u8>,
    buf_iter: str::SplitWhitespace<'static>,
}
impl<R: BufRead> Scanner<R> {
    fn new(reader: R) -> Self {
        Self { reader, buf_str: vec![], buf_iter: "".split_whitespace() }
    }
    fn token<T: str::FromStr>(&mut self) -> T {
        loop {
            if let Some(token) = self.buf_iter.next() {
                return token.parse().ok().expect("Failed parse");
            }
            self.buf_str.clear();
            self.reader.read_until(b'\n', &mut self.buf_str).expect("Failed read");
            self.buf_iter = unsafe {
                let slice = str::from_utf8_unchecked(&self.buf_str);
                std::mem::transmute(slice.split_whitespace())
            }
        }
    }
}

fn solve<R: BufRead, W: Write>(scan: &mut Scanner<R>, w: &mut W) {
    let n = scan.token::<i64>();
    let mut a: Vec<i64> = (0..n as usize).map(|_| scan.token()).collect();
    writeln!(w, "1 1\n{}", (n-1) * a[0]).ok();

    if n == 1 {
        writeln!(w, "1 1\n0").ok();
    } else {
        writeln!(w, "2 {}", n).ok();
        for i in 1..n as usize {
            write!(w, "{} ", (n-1) * a[i]).ok();
        }
        writeln!(w, "").ok();
    }

    writeln!(w, "1 {}", n).ok();
    for i in 0..n as usize {
        write!(w, "{} ", -n * a[i]).ok();
    }
    writeln!(w, "").ok();
}

fn main() {
    let (stdin, stdout) = (io::stdin(), io::stdout());
    let mut scan = Scanner::new(stdin.lock());
    let mut out = io::BufWriter::new(stdout.lock());
    solve(&mut scan, &mut out);
}