Cod sursa(job #1502092)

Utilizator justsomedudePalade Thomas-Emanuel justsomedude Data 14 octombrie 2015 10:02:12
Problema Transport Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.93 kb
#include<iostream>
#include<fstream>

using namespace std;

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

int main ()
{
  int n,k,a[16005],i,counting;
  int maxim = 0, ok;

  fin >> n >> k;

  for (i=1; i<=n; i++)
    {
       fin >> a[i];
       maxim = max(maxim, a[i]);
    }

  counting=1; ok=0;
  int camion=0;
  i=1;
  maxim++;
  while (ok==0)
{
  /// cout << counting;
  while (counting <= k)
  {

     if (camion + a[i] <= maxim)
     {
         camion += a[i];
         i++;
     }

     else /// nu mai incape nicio saltea in camion
     {
         camion = 0; /// s-a golit camionul
         counting++;   ///  s-a efectuat transportul
         i++;
     }
  }

  if (counting == k+1)
     {
        ok = 1;
        fout << maxim << "\n";
     }
  else
     {
        i = 1;
        maxim++;
        camion = 0;
     }
}
  fin.close();
  fout.close();
  return 0;
}