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 ;
using ll = long long ;
const int N = 2e5 + 5 ;
int n , x , a[N], l[N], r[N] ;
int findLIS() {
vector<int> d ;
for (int i = 1 ; i <= n ; i++) {
auto it = lower_bound(d.begin(), d.end(), a[i]) ;
if (it == d.end()) d.push_back(a[i]) ;
else *it = a[i] ;
}
return d.size() ;
}
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
cin >> n >> x ;
for (int i = 1 ; i <= n ; i++) {
cin >> a[i] ;
}
for (int i = 1 ; i <= n ; i++) {
l[i] = a[i] - x ;
r[i] = a[i] + x ;
}
int ret = findLIS() ;
if (!x) {
cout << ret ;
return 0 ;
}
for (int l = 1 ; l <= n ; l++) {
for (int r = l ; r <= n ; r++) {
for (int d = -x ; d <= x ; d++) {
if (x == 0) continue ;
for (int i = l ; i <= r ; i++) {
a[i] += d ;
}
ret = max(ret, findLIS()) ;
for (int i = l ; i <= r ; i++) {
a[i] -= d ;
}
}
}
}
cout << ret ;
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... |