Pagini recente » Cod sursa (job #1908480) | Cod sursa (job #2280788) | Cod sursa (job #2132142) | Cod sursa (job #908662) | Cod sursa (job #2937826)
#include <iostream>
#include <fstream>
using namespace std;
const int MAX = 16000 ;
const int VMAX = 256000000 ;
int a[MAX] , k , n ;
bool sepoate(int c)
{
int cc = 0 , nrt = 0 ;
for(int i = 0 ; i < n ; i ++)
{
if(a[i] > cc)
{
cc = c ;
nrt ++ ;
}
if(a[i] > cc)
{
return false ;
}
cc -= a[i] ;
}
return (nrt <= k);
}
int cautbin(int a[])
{
int rez ;
int st = 1 , dr = VMAX ;
while(st <= dr)
{
int mid = (st + dr) / 2 ;
if(sepoate(mid))
{
rez = mid ;
dr = mid - 1 ;
}
else
{
st = mid +1 ;
}
}
return rez ;
}
ifstream fin("transport.in");
ofstream fout("transport.out");
int main()
{
fin >> n >> k ;
for(int i = 0 ; i < n ; i ++)fin >> a[i] ;
fout << cautbin(a) ;
return 0;
}