Pagini recente » Cod sursa (job #3207340) | Cod sursa (job #2703390) | Cod sursa (job #3140991) | Cod sursa (job #3196340) | Cod sursa (job #2088869)
#include <cstdio>
using namespace std;
int lg;
int n, k, a[16001];
int numarare(int x)
{
int nr=1,s=0;
for(int i=1; i<=n; i++)
{
s+=a[i];
if(s>=x)
{
nr++;
s=0;
}
}
if(nr==k)
return 1;
return 0;
}
long long cautbin(long long lg, long long vmin)
{
long long i;
for(int i=vmin+1;i;i++)
if(numarare(i)==1)
return i;
return i;
}
int main()
{
freopen("transport.in", "r", stdin);
freopen("transport.out", "w", stdout);
scanf("%d %d", &n, &k);
long long vmin=-1;
for(int i=1; i<=n; i++)
{
scanf("%d", &a[i]);
if(a[i]>vmin)
vmin=a[i];
}
long long lg;
lg=1ll<<62;
printf("%lld",cautbin(lg,vmin));
return 0;
}