#include "sequence.h"
// #include "grader.cpp"
#include <bits/stdc++.h>
#include <vector>
#define lg long long
using namespace std;
const lg N = 2e3+5;
int sequence(int nO, vector<int> a)
{
lg ans = 1;
map<lg, lg> inc, dec;
bool flag = true;
vector<int> v = a;
sort(v.begin(), v.end());
for(int i = 0; i < nO; i++)
{
if(flag) inc[a[i]]++;
else dec[a[i]]++;
if(i && a[i] < a[i-1])
{
flag = false;
}
}
for(auto it : inc)
{
auto it2 = lower_bound(v.begin(), v.end(), it.first)-v.begin();
if(it2 >= nO/2)
{
// cout << it.first << ' ' << it2 << '\n';
ans = max(ans, it.second+dec[it.first]);
}
ans = max(ans, it.second);
}
for(auto it : dec)
{
auto it2 = lower_bound(v.begin(), v.end(), it.first)-v.begin();
if(it2 >= nO/2)
{
// cout << it.first << '\n';
ans = max(ans, it.second+inc[it.first]);
}
ans = max(ans, it.second);
}
return ans;
}
/*
14
2 6 2 5 3 4 2 1 4 3 5 6 3 2
9
1 1 2 3 4 3 2 1 1
7
1 2 3 1 2 1 3
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
238 ms |
36364 KB |
Output is correct |
3 |
Correct |
245 ms |
37940 KB |
Output is correct |
4 |
Correct |
41 ms |
6044 KB |
Output is correct |
5 |
Correct |
271 ms |
36356 KB |
Output is correct |
6 |
Correct |
254 ms |
34576 KB |
Output is correct |
7 |
Correct |
47 ms |
6096 KB |
Output is correct |
8 |
Correct |
49 ms |
6100 KB |
Output is correct |
9 |
Correct |
42 ms |
6092 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
447 ms |
53124 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |