This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int int64_t
int n, k;
bool f(vector<int> const& a, int m) {
int curk = 1, cur = 0;
bool flag = true;
for(int i = 1; i < n; i ++) {
if(a[i] - cur > m) {
if(flag) {
cur = a[i - 1];
flag = false;
}
else {
flag = true;
cur = a[i];
curk ++;
}
}
}
return curk <= k;
}
int32_t main() {
cin >> n >> k;
vector<int> a(n, 0);
for(int i = 1; i < n; i ++) {
int d, b, c;
cin >> d >> b >> c;
a[i] = c;
}
for(int i = 1; i < n; i ++) a[i] += a[i-1];
int l = 1, r = 1e18;
while(r - l > 1) {
int m = (l + r) >> 1;
bool cur = f(a, m);
if(cur) r = m;
else l = m + 1;
}
cout << r << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |