Pagini recente » Cod sursa (job #3290662) | Cod sursa (job #2885640) | Cod sursa (job #2592035) | Cod sursa (job #3242213) | Cod sursa (job #2937827)
#include <fstream>
using namespace std;
ifstream cin("transport.in");
ofstream cout("transport.out");
int n, t;
const int CMAX = 256e6;
const int N = 16e3;
int v[N];
bool se_poate(int c){
int cc = 0, nrt = 0;
for(int i = 0;i<n;i++){
if(v[i] > cc){
cc = c;
nrt++;
}
if(nrt > t){
return false;
}
cc -= v[i];
}
return true;
}
int main(){
int rez, dr, st;
cin>>n>>t;
st = 1;
dr = CMAX;
rez = CMAX + 1;
for(int i = 0;i<n;i++){
cin>>v[i];
st = max(st, v[i]);
}
while(st <= dr){
int m = (st + dr) /2;
if(se_poate(m)){
rez = m;
dr = m- 1;
}else{
st = m + 1;
}
}
cout<<rez;
cin.close();
cout.close();
return 0;
}