Pagini recente » Cod sursa (job #2261961) | Cod sursa (job #1218926) | Cod sursa (job #641596) | Cod sursa (job #2175382) | Cod sursa (job #2480667)
#include <fstream>
#include<iostream>
#include<vector>
using namespace std;
#define eps 1e-6
ifstream f("transport.in");
ofstream g("transport.out");
int n,k,m;
vector<double> v;
int calc(int x){
int y=0,p=1;
for(int i=0;i<n;i++)
{
y+=v[i];
if(y>x)
{
p++;
y=v[i];
}
}
if(p<=k) return 1;
return 0;
}
int caut(int a, int b){
while(a<=b)
{
int c=(b+a)/2;
if(calc(c)==0) a=c+1;
else b=c-1;
}
return b+1;
}
int main()
{
f>>n>>k;
for(int i=0;i<n;i++)
{
int x;
f>>x,v.push_back(x);
if(x>m) m=x;
}
g<<caut(m,1000000000);
return 0;
}