#include <bits/stdc++.h>
using ll = long long;
int main(){
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
std::cin >> n;
std::vector<std::pair<ll , ll>>s(n);
std::vector<ll>a(n) , p( n , 1);
for(int i = 0 ; i < n ; i++){
std::cin >> a[i];
s[i].first = a[i];
s[i].second = i;
}
if(n ==1 ){
std::cout << 1;
return 0;
}
else{
std::sort(s.begin() , s.end());
ll isl= 1 , max = -1e9;
ll i = 0;
for(int i = 0; i < n; i++){
if(i >0){
if(s[i].first != s[i-1].first){
max = std::max(isl , max);
}
}
ll idx = s[i].second;
ll val = s[i].first;
if(idx == 0){
if(p[idx + 1] == 0){
isl = isl -1;
}
}
else if(idx == n-1){
if(p[idx - 1] == 0){
isl = isl -1;
}
}
else{
if(p[idx-1] == 1 and p[idx+1] == 1){
isl = isl +1;
}
else if(p[idx-1] == 1 and p[idx+1] == 0 ){
isl = isl;
}
else if(p[idx-1] == 0 and p[idx+1] == 1 ){
isl = isl;
}
else{
isl = isl -1;
}
}
p[idx] = 0;
}
max = std::max(isl , max);
std::cout << max;
}
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... |