# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
1099532 |
2024-10-11T14:31:09 Z |
crispxx |
Stove (JOI18_stove) |
C++17 |
|
1 ms |
348 KB |
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vt vector
#define nl " \n"
#define pb emplace_back
#define all(x) x.begin(), x.end()
template <class F, class S>
void chmin(F &a, S b) {
if(a > b) a = b;
}
template <class F, class S>
void chmax(F &a, S b) {
if(a < b) a = b;
}
void run_case() {
int n, k;
cin >> n >> k;
vt<int> a(n);
for(auto &i : a) {
cin >> i;
}
auto f = [&](int x) -> pair<int, int> {
int sum = 0, cnt = 0, j = -1;
for(int i = 0; i < n; i++) {
if(i == 0) {
j = i;
cnt++;
continue;
}
if(a[i] - a[j] > x) {
sum += a[i - 1] - a[j] + 1;
j = i;
cnt++;
}
}
if(a[n - 1] - a[j] <= x) sum += a[n - 1] - a[j] + 1;
return {cnt, sum};
};
int l = 0, r = *max_element(all(a));
while(l < r) {
int mid = (l + r) / 2;
if(f(mid).first <= k) {
r = mid;
} else {
l = mid + 1;
}
}
cout << f(r).second << nl;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int tt = 1;
// cin >> tt;
for(int i = 0; i < tt; i++) {
run_case();
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |