Pagini recente » Cod sursa (job #2535640) | Cod sursa (job #2491347) | Cod sursa (job #3178330) | Cod sursa (job #2490424) | Cod sursa (job #3121513)
#include <fstream>
using namespace std;
ifstream fin("transport.in");
ofstream fout("transport.out");
const int N_MAX = 16e3;
const int VAL_MAX = 16e3;
int sp[N_MAX];
int nr_transporturi(int sp[], int n, int carry) {
int transporturi = 1, ant = 0;
for(int i = 0; i < n; ++i)
if(sp[i] - ant > carry){
transporturi++;
ant = sp[i];
}
return transporturi;
}
int main() {
int n, k;
fin >> n >> k >> sp[0];
for(int i = 1; i < n; ++i){
fin >> sp[i];
sp[i] += sp[i - 1];
}
int b = 1, e = N_MAX * VAL_MAX + 1, mid;//[b;e)
while(e - b > 1){
mid = (b + e) >> 1;
if(nr_transporturi(sp, n, mid) > k)
b = mid;
else
e = mid;
}
fout << b - 1 << '\n';
fin.close();
fout.close();
return 0;
}