# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1200107 | tegshzaya | Sequence (APIO23_sequence) | C++20 | 0 ms | 0 KiB |
#include<bits/stdc++.h>
#define ll long long
#define ss second
#define ff first
#define endl "\n"
#define pb push_back
using namespace std;
int sequence(int n,vector<ll> a){
int aa=0,c[105];
bool bb[105];
for(int i=0;i<n;i++){
priority_queue<int> pq;
priority_queue<int,vector<int>,greater<>> qp;
for(int j=i;j<n;j++){
c[a[j]]++;
if(pq.empty() || a[j]<=pq.top()){pq.push(a[j]);}
else{qp.push(a[j]);}
if(pq.size()>qp.size()+1){qp.push(pq.top());pq.pop();}
if(qp.size()>pq.size()+1){pq.push(qp.top());qp.pop();}
int ss=0;
if(pq.size()>=qp.size()){ss=max(ss,c[pq.top()]);}
if(qp.size()>=pq.size()){ss=max(ss,c[qp.top()]);}
bb[ss]=1;
aa=max(aa,ss);
}
for(int j=i;j<n;j++){
c[a[j]]--;
}
}
/*for(int i=1;i<=aa;i++){
assert(b[i]);
}*/
return aa;
}