Cod sursa(job #1027989)

Utilizator andrei_diaconuAndrei Diaconu andrei_diaconu Data 13 noiembrie 2013 13:10:23
Problema Transport Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.78 kb
#include <iostream>
#include <fstream>
using namespace std;

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

int n, i, st, dr, k, vol[1601], s, m, nr, sol;

int transport(int vol)
{
    int j, tra, sum;
    for(j=1; j<=n; j++)
    {
        if(sum + a[j]<=vol)
            sum+=a[j];
        else
        {
            sum=a[j];
            tra++;
        }
    }
    return tr;
}

int main()
{
    f>>n>>k;
    for(i=1;i<=n;i++)
    {
        f>>vol[i];
        s+=vol[i];
    }

    st=1;
    dr=s;

    while(st<=dr)
    {
        m=(st+dr)/2;
        nr=transport(m);
        if(nr<=k)
        {
            dr=m-1;
            sol=m;
        }
        else
        {
            st=m+1;
        }
    }
    g<<sol;
    return 0;
}