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>
#define MAXN 500007
using namespace std;
int n,a[MAXN],ans,c[MAXN];
int pref[MAXN],mins[MAXN],maxs[MAXN];
int solve(int val){
for(int i=1;i<=n;i++){
pref[i]=mins[i]=maxs[i]=0;
if(a[i]<val)mins[i]=1;
if(a[i]>val)maxs[i]=1;
if(a[i]==val)pref[i]=1;
}
for(int i=1;i<=n;i++){
pref[i]+=pref[i-1]; mins[i]+=mins[i-1]; maxs[i]+=maxs[i-1];
}
int res=0;
for(int i=1;i<=n;i++){
for(int f=i;f<=n;f++){
if(pref[f]-pref[i-1]>=abs( maxs[f]-maxs[i-1] - (mins[f]-mins[i-1]) ))res=max(res,pref[f]-pref[i-1]);
}
}
return res;
}
int sequence(int N, std::vector<int> A){
n=N;
for(int i=1;i<=n;i++){
a[i]=A[i-1];
}
for(int i=1;i<=n;i++){
ans=max(ans,solve(i));
}
return ans;
}
/*int main(){
cout<<sequence(9, {1, 1, 2, 3, 4, 3, 2, 1, 1})<<"\n";
cout<<sequence(14, {2, 6, 2, 5, 3, 4, 2, 1, 4, 3, 5, 6, 3, 2})<<"\n";
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... |