Pagini recente » Cod sursa (job #3157015) | Cod sursa (job #2291743) | Cod sursa (job #3218513) | Cod sursa (job #2315920) | Cod sursa (job #658991)
Cod sursa(job #658991)
#include <cstdio>
using namespace std;
int n, k;
int v[16001];
void citire()
{
freopen("transport.in", "r", stdin);
scanf("%d %d\n", &n, &k);
for(int i = 1; i <= n; i++)
{
scanf("%d\n", &v[i]);
}
fclose(stdin);
}
int maxVector()
{
int max = 0;
for(int i = 1; i <= n; i++)
{
if(v[i] > max)
max = v[i];
}
return max;
}
int rezolvare()
{
int actual = maxVector();
int i;
int sw = 0, sumaPartial;
int drumActual;
int location;
for(i = actual; !sw; i++)
{
drumActual = 1;
location = 1;
while(drumActual <= k && location <= n)
{
sumaPartial = 0;
while(sumaPartial + v[location] <= i && location <= n)
{
sumaPartial += v[location];
location++;
}
drumActual++;
}
if(--location == n)
sw = 1;
}
return --i;
}
void afisare()
{
freopen("transport.out", "w", stdout);
printf("%d", rezolvare());
fclose(stdout);
}
int main()
{
citire();
afisare();
return 0;
}