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;
string to_string(string s) {
return '"' + s + '"';
}
string to_string(const char* s) {
return to_string((string) s);
}
string to_string(bool b) {
return (b ? "true" : "false");
}
template <typename A, typename B>
string to_string(pair<A, B> p) {
return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <typename A>
string to_string(A v) {
bool first = true;
string res = "{";
for (const auto &x : v) {
if (!first) {
res += ", ";
}
first = false;
res += to_string(x);
}
res += "}";
return res;
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
cerr << " " << to_string(H);
debug_out(T...);
}
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
vector<int> dp;
void init(int n){
dp.resize(n , 1);
return ;
}
void fill_dp(vector<int> v){
int n = (int)v.size();
if(n == 0) return ;
vector<int> lis;
for(int i = 0 ; i < n ; i++){
int val = v[i];
auto q = lower_bound(lis.begin(),lis.end() , val);
int id = q - lis.begin();
if(q == lis.end()){
lis.emplace_back(val);
}
else{
*q = val;
}
dp[i] = id + 1;
}
return ;
}
int get_lis(vector<int> v){
int n = (int)v.size();
if(n == 0) return 0;
vector<int> lis;
for(int i = 0 ; i < n ; i++){
int val = v[i];
auto q = lower_bound(lis.begin(),lis.end() , val);
if(q == lis.end()){
lis.emplace_back(val);
}
else{
*q = val;
}
}
return (int)lis.size();
}
int main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n , x;
cin >> n >> x;
init(n);
vector<int> v(n);
for(int i = 0 ; i < n ; i++){
cin >> v[i];
}
fill_dp(v);
int best = 0;
for(int i = 0 ; i < n ; i++){
int val = v[i];
vector<int> s;
for(int j = i + 1 ; j < n ; j++){
if(v[j] + x > val) s.emplace_back(v[j] + x);
}
best = max(best , dp[i] + get_lis(s));
s.clear();
for(int j = i + 1 ; j < n ; j++){
if(v[j] > val - x) s.emplace_back(v[j]);
}
best = max(best , dp[i] + get_lis(s));
}
cout << best << '\n';
return 0;
}
# | 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... |