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;
#define eb emplace_back
#define pb push_back
#define ppb pop_back
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define cl(a,s) memset((a),0,sizeof((a)[0])*(s))
#define all(x) (x).begin() , (x).end()
#define fi first
#define se second
#define int int
using pii = pair<int,int>;
using ll = long long;
const int maxn = 2e5+5;
const int inf = 2e9;
const int mod = 1e9+7;
int n,x;
int a[maxn];
int d[maxn];
int ans[maxn];
int tmp[maxn];
int lis() {
int ret = -1;
d[0] = -inf;
for(int i=1;i<=n;i++) d[i] = inf;
for(int i=1;i<=n;i++) {
int pos = lb(d,d+n+1,a[i])-d;
d[pos] = a[i];
ans[i] = pos;
ret = max(ret,pos);
}
return ret;
}
int32_t main () {
//freopen("in","r",stdin); freopen("out","w",stdout);
ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
cin >> n >> x;
for(int i=1;i<=n;i++) cin >> a[i];
for(int i=1;i<=n;i++) tmp[i] = a[i];
int ans = -inf;
for(int i=1;i<=n;i++)
for(int j=i;j<=n;j++)
for(int k=-x;k<=x;k++) {
for(int i=1;i<=j;i++) a[i] += k;
int res = lis();
if(res > ans) {
//cout << res << " " << ans << endl;
//cout << i << " " << j << " " << k << endl;
ans = res;
}
for(int i=1;i<=j;i++) a[i] = tmp[i];
}
cout << ans << endl;
}
# | 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... |