#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
using namespace std;
#define int long long
const int maxn = 100'001;
const int inf = 1e18;
int dp[maxn];
int dp1[maxn];
pair<int, int> eval(int lambda, vector<int> &t) {
const int n = t.size();
fill(dp, dp + maxn, inf);
fill(dp1, dp1 + maxn, inf);
dp[0] = 0;
dp1[0] = 0;
set<pair<int, int>> s;
for (int i = 1; i <= n; ++i) {
s.insert({ dp[i - 1] - t[i - 1] + 1 + lambda, dp1[i - 1] + 1 });
auto [val, cnt] = *s.begin();
dp[i] = val + t[i - 1];
dp1[i] = cnt + 1;
}
return { dp[n], dp1[n] };
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
vector<int> t(n);
for (int& i : t) {
cin >> i;
}
int l = -1, r = 2e9;
while (l + 1 < r) {
int m = (l + r) / 2;
if (eval(m, t).second > k) {
l = m;
} else {
r = m;
}
}
auto [a, b] = eval(r, t);
cout << a - k * r;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1876 KB |
Output is correct |
2 |
Correct |
6 ms |
1876 KB |
Output is correct |
3 |
Incorrect |
4 ms |
1876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1876 KB |
Output is correct |
2 |
Correct |
6 ms |
1876 KB |
Output is correct |
3 |
Incorrect |
4 ms |
1876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1876 KB |
Output is correct |
2 |
Correct |
6 ms |
1876 KB |
Output is correct |
3 |
Incorrect |
4 ms |
1876 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |