Cod sursa(job #2182183)

Utilizator cezarus30cezarus30 cezarus30 Data 22 martie 2018 10:54:38
Problema Transport Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.71 kb
#include <fstream>

using namespace std;

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

int n,v[16001],k;

bool sepoate(int c)
{
    int nr=0,cc=0;
    for(int i=0; i<n; i++)
    {
        if(v[i]>cc)
        {
            nr++;
            cc=c;
        }
        if(v[i]>cc)
        {
            return false;
        }
        if(nr>k)
        {
            return false;
        }
        cc-=v[i];
    }
    return true;
}
const int L=27;

int main()
{
    int j,i;
    in>>n>>k;
    for(int i=0; i<n; i++)
    {
        in>>v[i];

    }
    int r=0,pas=1<<L;
    while(pas!=0)
    {
        if(!sepoate(r+pas))
        {
            r+=pas;

        }
        pas/=2;
    }
    out<<r+1;
    return 0;
}