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;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, d, t;
cin >> n >> d >> t;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
const long long inf = 2e16;
vector<pair<long long, int>> dp(n + 1, {inf, 0});
auto Check = [&](long long x) {
dp = vector<pair<long long, int>>(n + 1, {inf, 1e9});
dp[n] = {0, 0};
for (int i = n - 1; i >= 0; i--) {
int mn = 1e9;
int delta = 0;
for (int j = i; j < n; j++) {
mn = min(mn, a[j]);
if (mn <= t) {
delta += 1;
}
dp[i] = min(dp[i], {dp[j + 1].first + x + delta, dp[j + 1].second + 1});
}
}
return dp[0].second <= d;
};
long long l = 0, r = inf, ans = 0;
while (l <= r) {
int mid = l + r >> 1;
if (Check(mid)) {
ans = mid;
r = mid - 1;
} else {
l = mid + 1;
}
}
Check(ans);
cout << dp[0].first - ans * dp[0].second - ans << '\n';
return 0;
}
Compilation message (stderr)
prison.cpp: In function 'int main()':
prison.cpp:34:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
34 | int mid = l + r >> 1;
| ~~^~~| # | 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... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |