//Problem link>>http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2408
#include <bits/stdc++.h>
using namespace std ;
int ves ,con , i , a[10000] ;
int call (int n)
{
int i=1 , k=1 , now=0 ;
while (k <= con)
{
if (i > ves) return 1 ;
if (now+a[i]<=n)
{
now+=a[i] ;
i++ ;
}
else
{
now=0 ;
k++ ;
}
}
return 0 ;
}
int main ()
{
while (cin>>ves>>con)
{
int sum=0 ;
for (i=1 ; i<=ves ; i++)
{
cin>>a[i] ;
sum=sum+a[i] ;
}
int low=0 , high=sum ,ans=0 ;
while (low<=high)
{
int mid=(low+high)/2 ;
if (call(mid) == 0) low=mid+1 ;
else
{
ans=mid ;
high=mid-1 ;
}
}
cout<<ans<<endl ;
}
return 0 ;
}
#include <bits/stdc++.h>
using namespace std ;
int ves ,con , i , a[10000] ;
int call (int n)
{
int i=1 , k=1 , now=0 ;
while (k <= con)
{
if (i > ves) return 1 ;
if (now+a[i]<=n)
{
now+=a[i] ;
i++ ;
}
else
{
now=0 ;
k++ ;
}
}
return 0 ;
}
int main ()
{
while (cin>>ves>>con)
{
int sum=0 ;
for (i=1 ; i<=ves ; i++)
{
cin>>a[i] ;
sum=sum+a[i] ;
}
int low=0 , high=sum ,ans=0 ;
while (low<=high)
{
int mid=(low+high)/2 ;
if (call(mid) == 0) low=mid+1 ;
else
{
ans=mid ;
high=mid-1 ;
}
}
cout<<ans<<endl ;
}
return 0 ;
}
welcome
ReplyDelete