Cod sursa(job #1029530)

Utilizator popovicirobpopovici robert popovicirob Data 15 noiembrie 2013 14:56:12
Problema Transport Scor 0
Compilator c Status done
Runda Arhiva de probleme Marime 0.85 kb
#include <stdio.h>
#include <stdlib.h>
int v[16000];
int main()
{   FILE*fi,*fout;
    int i,j,n,k,max,max1,s,flag,con;
    fi=fopen("transport.in" ,"r");
    fout=fopen("transport.out" ,"w");
    fscanf(fi,"%d %d" ,&n,&k);
    max=0;
    for(i=0;i<n;i++)
    {
      fscanf(fi,"%d" ,&v[i]);
      if(max<v[i])
       max=v[i];
    }
    flag=1;
    while(flag)
    {
        con=0;
        j=0;
        max1=0;
        while(j<n&&con<k)
        {
            s=0;
            while(j<n&&max>s)
            {
                s=s+v[j];
                j++;
            }
            if(s>max1)
             max1=s;
            con++;
        }
        if(con<=k)
        {
            flag=0;
            fprintf(fout,"%d" ,max1);
        }
        else
          max++;

    }
    fclose(fi);
    fclose(fout);
    return 0;
}