Cod sursa(job #658991)

Utilizator repp4raduRadu-Andrei Szasz repp4radu Data 9 ianuarie 2012 21:26:14
Problema Transport Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.18 kb
#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;
}