Cod sursa(job #2369997)

Utilizator riordache58Razvan Iordache riordache58 Data 6 martie 2019 10:11:25
Problema Transport Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.81 kb
#include <bits/stdc++.h>
#include <fstream>

#define NMAX 16005

using namespace std;

ifstream f("transport.in");
ofstream g("transport.out");

long long int n , k , i , a[NMAX] , c , s;

bool ver ( int x )
{
    int cnt;

    cnt = 1;

    int sum;

    sum = 0;

    int i;

    i = 0;

    for ( i = 0 ; i < n ; i ++ )
    {
        sum += a[i];
        if ( sum > x )
        {
            sum = a[i];

            cnt ++;
        }

        if ( cnt > k )
            return 0;
    }

    return 1;
}

int main()
{
    f >> n >> k;

    c = 0;


    s = 0;

    for ( i = 0 ; i < n; i ++ )
    {
        f >> a[i];

        s += a[i];

        if ( c < a[i] )
            c = a[i];
    }

    while ( ! ver( c ) )
        c ++;

    g << c;

	return 0;
}