Cod sursa(job #2858991)

Utilizator TeodorVTeodorV TeodorV Data 28 februarie 2022 18:26:56
Problema Transport Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.57 kb
#include <iostream>

using namespace std;

//ifstream fin("transport.in");
//ofstream fout("transport.in");

int v[16001],n,k,c;

bool verif()
{
    int s=0,t=0;
    for(int i=0; i<n; i++)
    {
        s+=v[i];
        if(s>c)
        {
            s=0;
            t++;
            i--;
        }
    }
    t++;
    return (t<=k);
}

int main()
{
    cin>>n>>k;
    for(int i=0; i<n; i++)
    {
        cin>>v[i];
        if(c<v[i])
            c=v[i];
    }
    while(verif()==0)
    {
        c++;
    }
    cout<<c;
    return 0;
}