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 <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 |
---|
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... |