Cod sursa(job #95357)

Utilizator gabitzish1Gabriel Bitis gabitzish1 Data 28 octombrie 2007 14:00:11
Problema Transport Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.64 kb
#include<stdio.h>

int v[16010], k, n, max, nr, s;

void citire()
{
  freopen("transport.in","r",stdin);
  freopen("transport.out","w",stdout);
  scanf("%d %d",&n,&k);
  int i;
  for (i=1; i<=n; i++){ scanf("%d",v+i); if (max<v[i]) max=v[i];}
  nr=max;
}

void calcul()
{
  int i, j, ok=1;
  ok=1;
  while (ok)
  {
    i=1;
    j=0;
    int ok2=1;
    while (i<=n && ok2)
    {
      s=0;
      while (s<nr && i<=n) {s+=v[i]; i++;}
      if (s>nr) i--;
      j++;
      if (j>k) ok2=0;
    }
    if (i>n && ok2) ok=0;
    else nr++;
  }
  printf("%d\n",nr);
}

int main()
{
  citire();
  calcul();
  return 0;
}