/*input
3 6
1 3 4
*/
#include <bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define pi pair<long long,long long>
#define pii pair <ll,pi>
#define F(i,a,b) for(ll i = (ll)(a); i <= (ll)(b); i++)
#define RF(i,a,b) for(ll i = (ll)(a); i >= (ll)(b); i--)
#define PI 3.14159265
#define ll long long
#define ff first
#define ss second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define debug(x) cout << #x << " = " << x << endl
#define INF 1000000009
#define mod 1000000007
priority_queue < pii, vector<pii> > pq;
map <pi,ll> mymap;
ll a[500005],sum[500005]={0};
int main()
{
std::ios::sync_with_stdio(false);
mymap.clear();
while(!pq.empty())
pq.pop();
ll n,k;
cin>>n>>k;
F(i,1,n)
{
cin>>a[i];
sum[i] += sum[i-1]+a[i];
}
pq.push(mp(sum[n],mp(1,n)));
while(k--)
{
ll val = pq.top().ff;
cout<<val<<" ";
ll l = pq.top().ss.ff;
ll r = pq.top().ss.ss;
//cout<<l<<" "<<r<<" ";
pq.pop();
mymap[mp(l,r)] = 1;
if(l!=r)
{
val = sum[r]-sum[l];
if(!mymap[mp(l+1,r)])
{
pq.push(mp(val,mp(l+1,r)));
//cout<<l+1<<" "<<r<<" ";
mymap[mp(l+1,r)]=1;
}
val = sum[r-1]-sum[l-1];
if(!mymap[mp(l,r-1)])
{
pq.push(mp(val,mp(l,r-1)));
mymap[mp(l,r-1)]=1;
//cout<<l<<" "<<r-1<<endl;
}
}
//cout<<endl;
}
return 0;
}
LyppbnB1dAozIDYKMSAzIDQKKi8KI2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNpbmNsdWRlPHN0ZGlvLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgcGkgcGFpcjxsb25nIGxvbmcsbG9uZyBsb25nPgojZGVmaW5lIHBpaSBwYWlyIDxsbCxwaT4KI2RlZmluZSBGKGksYSxiKSBmb3IobGwgaSA9IChsbCkoYSk7IGkgPD0gKGxsKShiKTsgaS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