Cod sursa(job #1881256)
Utilizator | Data | 16 februarie 2017 12:10:29 | |
---|---|---|---|
Problema | Transport | Scor | 0 |
Compilator | cpp | Status | done |
Runda | Arhiva de probleme | Marime | 0.49 kb |
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int n,k,rs;
ll a[16010],st,dr;
bool ver(int v)
{ int s=0,rs=1;
for(int i=1;(i<=n)&&(rs<=k);i++){
s+=a[i];
if(s>v){rs++;s=a[i];}
}
return rs<=k;
}
int main()
{
cin>>n>>k;
st=1;dr=16001;
for(int i=1;i<=n;i++) cin>>a[i];
while(st<dr-3)
{
int mid=(st+dr)/2;
if(ver(mid)) dr=mid;
else st=mid;}
for(int i=st;i<=dr;i++)
if(ver(i)) return cout<<i,0;
}