This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")
#include"bits/stdc++.h"
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991
// joi 2018 not aliens trick :(
int n, k;
int a[100001];
signed main () {
cin.tie(0)->sync_with_stdio(0);
cin >> n >> k;
for (int i = 0 ; i < n ; i++) cin >> a[i];
int l = 0, r = 1000000000;
while (r - l > 1) {
int m = (l + r) / 2;
int prev = -1000000000;
int cnt = 0, tot = 0;
for (int i = 0 ; i < n ; i++) {
if (tot + (a[i] + 1) - prev > m) {
cnt++;
tot = 1;
prev = a[i];
} else {
tot += (a[i] + 1) - prev;
}
}
if (cnt <= k) r = m;
else l = m;
}
cout << r << endl;
}
Compilation message (stderr)
stove.cpp:17:1: warning: multi-line comment [-Wcomment]
17 | //\
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |