Pagini recente » Cod sursa (job #3222826) | Cod sursa (job #2055568) | Cod sursa (job #2948331) | Cod sursa (job #668331) | Cod sursa (job #1984042)
#include <vector>
#include <iostream>
#include <algorithm>
#include <map>
#include <utility>
#include<iostream>
#include<queue>
#include<utility>
#define RRR ios_base::sync_with_stdio(false);cin.tie(0);
#define ll long long
#define int ll
#define pp pair<int,int>
using namespace std;
vector<int> ar;
int n;
int k;
int i;
bool check(int c)
{
int s = 0;
int j = 0;
for ( i=0;i<n && j<k;i++)
{
if (s+ar[i] < c)
{
s += ar[i];
}
else
{
if (s != 0)
{
s = 0;
j++;
i--;
}
else return 0;
}
}
if (i < n || j > k )
return 0;
return 1;
}
int32_t main()
{
RRR
// freopen("text.txt","r",stdin);
freopen("transport.in","r",stdin);
freopen("transport.out","w",stdout);
cin >> n >> k;
for (int i=0;i<n;i++)
{
int z;
cin >> z;
ar.push_back(z);
}
//sort(ar.begin(),ar.end());
int m;
int l = 1;
int high = 1600*1600;
while (l <= high)
{
m = (l+high)/2;
if (check(m))
high = m-1;
else l = m+1;
}
cout << high;
return 0;
}