Cod sursa(job #1023718)

Utilizator japjappedulapPotra Vlad japjappedulap Data 7 noiembrie 2013 17:05:57
Problema Transport Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.7 kb
// :: BruteForce ::

#include <fstream>
using namespace std;

ifstream is ("transport.in");
ofstream os ("transport.out");

int a[16001], n, k, sol;
bool Found;
int cnt, s;

int main()
{
    is >> n >> k;
    for (int i = 1; i <= n; ++i)
    {
        is >> a[i];
        if (a[i] > sol)
            sol = a[i];
    }
    while (Found == false)
    {
        cnt = 0;
        s = 0;
        for (int i = 1; i <= n; ++i)
        {
            s += a[i];
            if (s + a[i+1] > sol)
                cnt++, s = 0;
        }
        if (cnt == k-1)
            Found = true;
        sol++;
    }
    sol--;
    os << sol;
    is.close();
    os.close();
    return 0;
}