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 "sequence.h"
#include <vector>
#include <bits/stdc++.h>
using namespace std;
int sequence(int N, std::vector<int> a) {
int ans = 0;
for (int i = 0; i < N; i++) {
priority_queue<int> front;
priority_queue<int, vector<int>, greater<int>> back;
map<int, int> cnt;
for (int j = i; j < N; j++) {
front.push(a[j]);
cnt[a[j]]++;
while (front.size() - back.size() >= 2) {
back.push(front.top());
front.pop();
}
while (back.size() && front.top() > back.top()) {
int A = front.top(); front.pop();
int B = back.top(); back.pop();
back.push(A); front.push(B);
}
if (front.size() == back.size()) {
int m1 = front.top();
int m2 = back.top();
ans = max(ans, cnt[m1]);
ans = max(ans, cnt[m2]);
}
else {
int m1 = front.top();
ans = max(ans, cnt[m1]);
}
}
}
return ans;
}
// #include "grader.cpp"
# | 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... |