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 <bits/stdc++.h>
using namespace std;
using ll = long long;
int sequence(int n, std::vector<int> a) {
ll mx = 0;
for (int i = 0; i < n; ++i)
{
map < int, ll > m;
int mid = -1, mi = 0;
for (int j = i; j >= 0; --j)
{
++m[a[j]];
ll ans = 0;
if (mid == -1) mid = a[j];
if (a[j] < mid) ++mi;
if ((i - j + 1) / 2 < mi) mid = prev (m.find (mid))->first, mi -= m[mid];
if (mi + m[mid] < (i - j + 1) / 2) mi += m[mid], mid = next (m.find (mid))->first;
ans += m[mid];
if (mi + m[mid] < (i - j + 2) / 2) ans = max (ans, next (m.find (mid))->second);
mx = max (mx, ans);
}
}
return mx;
}
# | 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... |