이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
#define endl '\n'
#define pl(var) " [" << #var << ": " << (var) << "] "
#define ll long long
void solve() {
// get the longest sequence satisfying this
int n, h; cin >> n >> h;
vector<int> arr(n + 1);
for (int i = 1; i <= n; i++) cin >> arr[i];
vector<int> dp(n + 1, 0);
dp[0] = 0;
for (int i = 1; i <= n; i++) {
// dp[i] = 1;
// cout << pl(i) << endl;
if (i * h >= arr[i]) {
dp[i] = 1;
} else {
continue;
}
for (int j = i - 1; j >= 1; j--) {
// cout << pl(j) << pl(dp[j]) << pl(arr[j]) << endl;
if (arr[j] >= arr[i]) {
dp[i] = max(dp[i], dp[j] + 1);
} else if (arr[j] + (i - j) * h >= arr[i]) {
dp[i] = max(dp[i], dp[j] + 1);
}
}
// cout << pl(dp[i]) << endl;
}
int ans = 0;
for (int i = 0; i <= n; i++) ans = max(ans, dp[i]);
cout << (n - ans) << endl;
}
int main() {
// freopen(".in", "r", stdin);
// freopen(".out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(nullptr);
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... |