This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
using namespace std;
#include <iostream>
#include <vector>
#include <set>
vector<int> v;
int n,z,x,a,b;
int sub4(){
set<int> s;
for (int i=0;i<n;i++){
a=v[i];
if (s.lower_bound(a)==s.end()){
s.insert(a);
}else{
s.erase(s.lower_bound(a));
s.insert(a);
}
}
return s.size();
}
int sub12(){
z=0;
for (int i=0;i<n;i++){
for (int j=i;j<n;j++){
for (int k=-x;k<=x;k++){
for (int l=i;l<=j;l++){
v[l]+=k;
}
z=max(z,sub4());
for (int l=i;l<=j;l++){
v[l]-=k;
}
}
}
}
return z;
}
int sub6(){
vector<int> l;
vector<int> r;
l.resize(n);
r.resize(n);
set<int> s;
set<int,greater<int>> t;
for (int i=0;i<n;i++){
a=v[i];
if (s.lower_bound(a)==s.end()){
s.insert(a);
}else{
s.erase(s.lower_bound(a));
s.insert(a);
}
l[i]=s.size();
}
for (int i=n-1;i>=0;i--){
a=v[i];
if (t.lower_bound(a)==t.end()){
t.insert(a);
}else{
t.erase(t.lower_bound(a));
t.insert(a);
}
r[i]=t.size();
}
z=l[n-1];
for (int i=0;i<n-1;i++){
z=max(z,l[i]+r[i+1]);
}
return z;
}
int main(){
cin>>n>>x;
v.resize(n);
for (int i=0;i<n;i++){
cin>>v[i];
}
if (x==0){
cout<<sub4();
}else if (n<=50&&x<=50){
cout<<sub12();
}else{
cout<<sub6();
}
}
# | 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... |