이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/*
* AUTHOR : Hydrolyzed~
* SCHOOL : RYW
* TASK : Global Warming
* ALGO : Dynamic Programming
* DATE : 23 Mar 2023
* */
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#ifndef _DEBUG
// @==== Libary ====@ //
// @================@ //
#endif
using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update> ;
// @=== Debugger ===@ //
#ifdef _DEBUG
#include "debug.hpp"
#else
#define dbg(...) 0
#endif
// @================@ //
using ll = long long;
const int MxN = 1010;
int dp[MxN], dp2[MxN], a[MxN];
inline void solution(){
int n, x;
cin >> n >> x;
for(int i=1; i<=n; ++i){
cin >> a[i];
}
dp[1] = 1;
for(int i=2; i<=n; ++i){
dp[i] = 1;
for(int j=i-1; j>=1; --j){
if(a[i] > a[j]){
dp[i] = max(dp[i], dp[j] + 1);
}
}
}
dp2[n] = 1;
for(int i=n-1; i>=1; --i){
dp2[i] = 1;
for(int j=i+1; j<=n; ++j){
if(a[i] < a[j]){
dp2[i] = max(dp2[i], dp2[j] + 1);
}
}
}
int answer = *max_element(dp + 1, dp + n + 1);
for(int i=1; i<=n; ++i){
for(int j=i+1; j<=n; ++j){
if(a[i] - a[j] < x){
answer = max(answer, dp[i] + dp2[j]);
}
}
}
cout << answer;
return ;
}
signed main(){
cin.tie(nullptr)->ios::sync_with_stdio(false);
int q = 1;
// cin >> q;
while(q--){
solution();
cout << "\n";
}
return 0;
}
// https://github.com/MasterIceZ/archive/tree/main/cpp-template
# | 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... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |