Pagini recente » Cod sursa (job #411317) | Cod sursa (job #2850971) | Cod sursa (job #1274955) | Cod sursa (job #303062) | Cod sursa (job #93832)
Cod sursa(job #93832)
#include<fstream.h>
ifstream f("transport.in");
ofstream g("transport.out");
long long int a[16000],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;
}