Pagini recente » infoarena - comunitate informatica, concursuri de programare | Cod sursa (job #68884) | Cod sursa (job #1961504) | Cod sursa (job #360644) | Cod sursa (job #594107)
Cod sursa(job #594107)
#include <cstdio>
using namespace std;
int a[16005],n,k;
int verif(int cap){
int i=0,s,nr=0;
while (i < n){
s=0;
while (s <= cap)
s+=a[i++];
i--;
nr++;
}
return nr;
}
int main(){
freopen("transport.in","r",stdin);
freopen("transport.out","w",stdout);
scanf("%d",&n);
scanf("%d",&k);
int max=0;
for (int i=0; i<n; ++i){
scanf("%d",a+i);
max=a[i]>max?a[i]:max;
}
int v=verif(max);
while (v > k)
v=verif(max++);
printf("%d",--max);
return 0;
}