This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// 027 072 207 270 702 720
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(), x.end()
#define fo(i, a, b) for (int i = (a), b_ = (b); i <= b_; ++i)
#define fod(i, a, b) for (int i = (a), b_ = (b); i >= b_; --i)
#define rep(i, n) fo(i, 1, n)
#define per(i, n) fod(i, n, 1)
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)
const int N = 1e6+5;
int n, m, a[N], dp[N];
bool reach[N];
void sol() {
cin >> n >> m;
a[0] = 0; reach[0] = 1;
rep(i, n) {
cin >> a[i];
for (int j = 0; j < i; ++j)
if (a[j] >= a[i] - m && reach[j])
chmax(dp[i], dp[j]+1);
if (dp[i] > 0) reach[i] = 1;
}
cout << n - *max_element(dp+1, dp+n+1);
}
signed main() {
cin.tie(0) -> sync_with_stdio(0);
if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
int tc = 1, test = 0; // cin >> tc;
while (++test <= tc) sol();
}
Compilation message (stderr)
triusis.cpp: In function 'int main()':
triusis.cpp:33:35: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
33 | if (fopen("A.inp", "r")) freopen("A.inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
# | 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... |