#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define ld long double
using namespace std;
const int N = 1000003;
const int MOD = 1e9 + 7;
void solve(){
int n;
cin >> n;
int mn = INT_MAX;
vector<pair<int, int> > a(n);
for(int i = 0; i < n; ++i){
cin >> a[i].first;
a[i].second = i;
mn = min(mn, a[i].first);
}
vector<bool> mp(n + 1);
int cur = mn, ans = 0;
for(int j = 0; j < n; ++j){
int x = j;
while(a[x].first > cur and x < n)
++x;
if(x != j){
j = x - 1;
++ans;
}
}
sort(a.begin(), a.end());
int res = ans;
mp[a[0].second] = true;
for(int i = 1; i < n; ++i){
mp[a[i].second] = true;
if(a[i].first == a[i - 1].first) continue;
int x = a[i].first;
for(int j = i; j < n; ++j){
if(a[j].first != x) break;
int k = a[j].second;
if(k >= 1 and mp[k - 1] and mp[k + 1]){
--ans;
mp[k] = true;
continue;
}
if(k >= 1 and mp[k - 1]){
if(k == n - 1) --ans;
mp[k] = true;
continue;
}
if(mp[k + 1]){
if(k == 0) --ans;
mp[k] = true;
continue;
}
if(k != 0 and k != n - 1)
ans++;
mp[k] = true;
}
res = max(res, ans);
}
cout << res << "\n";
}
int main(){
fast;
int t = 1;
// cin >> t;
while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
1 ms |
204 KB |
Output is correct |
4 |
Correct |
1 ms |
204 KB |
Output is correct |
5 |
Correct |
1 ms |
204 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
1112 KB |
Output is correct |
2 |
Correct |
19 ms |
1100 KB |
Output is correct |
3 |
Correct |
20 ms |
1100 KB |
Output is correct |
4 |
Correct |
18 ms |
1112 KB |
Output is correct |
5 |
Correct |
22 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
21 ms |
1108 KB |
Output is correct |
2 |
Correct |
16 ms |
1108 KB |
Output is correct |
3 |
Correct |
24 ms |
1112 KB |
Output is correct |
4 |
Correct |
23 ms |
1108 KB |
Output is correct |
5 |
Correct |
20 ms |
1100 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
239 ms |
8272 KB |
Output is correct |
2 |
Correct |
239 ms |
17620 KB |
Output is correct |
3 |
Correct |
241 ms |
17608 KB |
Output is correct |
4 |
Correct |
241 ms |
17736 KB |
Output is correct |
5 |
Correct |
214 ms |
16968 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
8144 KB |
Output is correct |
2 |
Correct |
240 ms |
16828 KB |
Output is correct |
3 |
Correct |
230 ms |
16836 KB |
Output is correct |
4 |
Correct |
204 ms |
11080 KB |
Output is correct |
5 |
Correct |
199 ms |
11068 KB |
Output is correct |