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;
template<typename T> bool umax(T &res, const T &val) { if (res < val){ res = val; return true; }; return false; }
template<typename T> bool umin(T &res, const T &val) { if (res > val){ res = val; return true; }; return false; }
const int sz = 1e6 + 5;
#define int long long
struct DSU{
vector<int>e;
DSU(int n){
e.assign(n + 1, -1);
}
int _find(int v){
if(e[v] < 0){
return v;
}
return e[v] = _find(e[v]);
}
int _union(int u,int v){
u = _find(u);
v = _find(v);
if(u != v){
if(e[u] > e[v]){
swap(u, v);
}
e[u] += e[v];
e[v] = u;
return 1;
}
return 0;
}
};
vector<int>a(sz), dp(sz, 1);
void test_case(int testcase){
int n, d;
cin >> n >> d;
for(int i = 0; i < n; ++i){
cin >> a[i];
}
int res = 0;
for(int i = 0; i < n; ++i){
for(int j = max(0LL, i - d); j < i; ++j){
if(a[i] > a[j]){
dp[i] = max(dp[i], dp[j] + 1);
}
}
umax(res, dp[i]);
}
cout << dp[n - 1] << endl;
}
signed main(){
int T = 1;
for(int test = 1; test <= T; ++test){
test_case(test);
}
}
/*
*/
# | 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... |