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 libraries */
using namespace std;
using ld = long double;
template <class T>
using vc = vector <T>;
using pii = pair <int, int>;
using pint = pair <int, int>;
template<class T>
bool chmax(T &a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template<class T>
bool chmin(T &a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
const int N = 5e5;
const int inf = 1e9;
int a[N], t, n;
pii check (int x) {
vc <pii> dp(n + 1, {inf, 0});
auto cmp = [&](pii a, pii b) {
if (a.first + a.second * x == b.first + b.second * x)
return a.second < b.second;
return a.first + a.second * x < b.first + b.second * x;
};
dp[0] = {0, 0};
for (int i = 0; i < n; ++i) {
int mn = a[i], cnt = 0;
for (int j = i; j < n; ++j) {
if (mn <= t) {
++cnt;
}
dp[j + 1] = min(dp[j + 1], {dp[i].first + cnt, dp[i].second + 1}, cmp);
if (j < n - 1)
mn = min(mn + 1, a[j + 1]);
}
}
return dp[n];
}
void solve() {
int d;
cin >> n >> d >> t;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
int l = -1, r = inf;
while (r - l > 1) {
int m = (l + r) / 2;
pii v = check(m);
if (v.second - 1 <= d) {
r = m;
} else {
l = m;
}
}
pii v = check(r);
cout << v.first << '\n';
}
signed main() {
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int t = 1;
// cin >> t;
while (t--) solve();
}
# | 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... |