Cod sursa(job #93829)
Utilizator | dan horia bobo_2 | Data | 20 octombrie 2007 14:09:00 |
---|---|---|---|
Problema | Transport | Scor | 30 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.53 kb |
#include<fstream.h>
ifstream f("transport.in");
ofstream g("transport.out");
long long int a[500],n,m,s,max,nrt,k,i;
int main()
{ f>>n>>k;
for(i=1;i<=n;i++)
f>>a[i];
max=0;
for(i=1;i<=n;i++)
if(a[i]>max) max=a[i];
nrt=0;
i=1;
while(i<=n)
{ if(nrt<k) { s=0;
while(s<=max)
{ s+=a[i++];
}
nrt++;
i=i-1;
}
else { max++; i=1; nrt=0; }
}
g<<max;
f.close();
g.close();
return 0;
}