Pagini recente » Cod sursa (job #2896753) | Cod sursa (job #669670) | Cod sursa (job #2457886) | Cod sursa (job #52350) | Cod sursa (job #2615217)
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
using namespace std;
const int N = 16001;
int v[N], n;
int cautbin ( int curent, long long x){
int rez = 0, pas = 1 << 13;
while( pas != 0){
if( (rez + pas) <= n && v[rez + pas] - v[curent] < x)
rez += pas;
pas >>= 1;
}
return rez;
}
int main()
{
ifstream in ("transport.in");
ofstream out ("transport.out");
int k;
in >> n >> k;
for(int i = 1; i <= n; i++){
in >> v[i];
v[i] += v[i-1];
}
/*int s = ( v[n]/k ) + 1, d = 0;
if(s < maxim)
s = maxim;
int i = 0;
while ( i < n){
i = cautbin(i,s);
d++;
if(d > k){
i = 0;
s++;
d = 0;
}
}*/
long long pas = 1 << 27;
int rez = 0;
while( pas != 0){
if( rez + pas <= v[n]){
int i = 0, d = 0;
while ( i < n){
i = cautbin(i, rez + pas);
d++;
}
if( d > k )
rez += pas;
}
pas >>= 1;
}
out << rez;
return 0;
}