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;
int main(){
int n, x;
cin >> n >> x;
int a[n];
for(int i = 0;i < n; i++) cin >> a[i];
if(x == 0){
vector<int> dp;
for(int i = 0; i < n; i++){
int idx = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
if(idx == (int)dp.size()){
dp.push_back(a[i]);
}
else{
dp[idx] = a[i];
}
}
cout << dp.size() << "\n";
}
else{
if(n <= 1000){
int ans = 0;
for(int i = -1; i < n; i++){
int b[n];
for(int j = 0; j < n; j++){
if(j <= i){
b[j] = a[j] - x;
}
else{
b[j] = a[j];
}
}
vector<int> dp;
for(int j = 0; j < n; j++){
int idx = lower_bound(dp.begin(), dp.end(), b[j]) - dp.begin();
if(idx == (int)dp.size()){
dp.push_back(b[j]);
}
else{
dp[idx] = a[j];
}
}
ans = max(ans, (int)dp.size());
}
cout << ans << "\n";
}
}
}
# | 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... |