Cod sursa(job #2369675)

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

#define NMAX 16005

using namespace std;

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

int n , k , i , a[NMAX];

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;

    int maxx;

    maxx = 0;

    int s;

    s = 0;

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

        s += a[i];

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

    while ( ! ver( maxx ) )
        maxx ++;

    g << maxx;

	return 0;
}