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 v vector
#define int long long
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define mk make_pair
#define pii pair<int, int>
#define ff first
#define ss second
#define inp_v(vec) for (auto &i : vec) cin >> i;
#define prt_v(vec) for (auto i : vec) cout << i << endl;
#define MS(x) memset(x, 0, sizeof(x))
#define gcd(a,b) __gcd(a, b);
#define lcm(a,b) (a*(b/gcd(a,b)))
bool chmin(int &a, int b){return b<a?a=b, true:false;}
bool chmax(int &a, int b){return b>a?a=b, true:false;}
const int maxn=2e5+5;
int N, x;
int ans=1;
void cek(vector<int>A2){
int dpp[N+1];
for(int i=1;i<=N;i++){
dpp[i]=1;
}
for(int i=2;i<=N;i++){
for(int j=i-1;j>=1;j--){
if(A2[i]>A2[j])dpp[i]=max(dpp[i], dpp[j]+1);
}
ans=max(ans, dpp[i]);
}
return;
}
signed main(){
ios_base::sync_with_stdio(false); cin.tie(0);
cin>>N>>x;
vector<int>A(N+1), dp(N+1);
for(int i=1;i<=N;i++)cin>>A[i];
if(N<=50){
for(int i=1;i<=N;i++){
for(int k=-x;k<=x;k++){
auto temp=A;
for(int j=i;j<=N;j++){
temp[j]+=k;
// for(auto isi:temp)cout<<isi<<" ";
// cout<<endl;
cek(temp);
}
}
}
cout<<ans<<endl;
}
else if(!x){
multiset<pair<int, int>>st;
dp[N]=1;
st.insert({A[N], 1});
int ans=1;
for(int i=N-1;i>=1;i--){
auto it=st.upper_bound({A[i], 0});
if(it==st.end())dp[i]=1;
else{
dp[i]=(*it).second+1;
}
ans=max(ans, dp[i]);
auto lb=st.lower_bound({A[i], 0});
if(lb!=st.end()&&(*lb).first==A[i])st.erase(lb);
st.insert({A[i], dp[i]});
}
cout<<ans<<endl;
}
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... |