#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define pff pair<float, float>
#define coutpair(p) cout << p.first << " " << p.second << "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
const ll MAXN = 30000005;
ll dp[MAXN];
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n; cin >> n;
int prev = -1;
vector<pii> v;
int cur = 0;
int arr[n];
for (int i=0; i<n; i++){
int a; cin >> a;
if (prev == a) continue;
v.push_back({a, cur});
prev = a;
arr[cur] = a;
cur++;
}
sort(v.begin(), v.end(), greater<pii>());
if (v.size() == 1) {
cout << 1;
return 0;
}
int curans = 0;
int ans = 0;
for (int i = 0; i < cur; i++) {
pii c = v[i];
if (c.second == cur-1){
if (arr[c.second-1] <= c.first) curans++;
}
else if (c.second == 0){
if(arr[c.second+1] < c.first) curans++;
}
else{
if (arr[c.second-1] > c.first && arr[c.second+1] > c.first) curans--;
else if (arr[c.second-1] < c.first && arr[c.second+1] < c.first) curans++;
}
if (i == cur-1 || v[i].first != v[i+1].first) ans = max(ans, curans);
}
cout << ans;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
14 ms |
2268 KB |
Output is correct |
2 |
Correct |
14 ms |
2268 KB |
Output is correct |
3 |
Correct |
14 ms |
2140 KB |
Output is correct |
4 |
Correct |
14 ms |
2268 KB |
Output is correct |
5 |
Correct |
14 ms |
2268 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
17 ms |
2612 KB |
Output is correct |
2 |
Correct |
11 ms |
2484 KB |
Output is correct |
3 |
Correct |
16 ms |
2524 KB |
Output is correct |
4 |
Correct |
16 ms |
2780 KB |
Output is correct |
5 |
Correct |
15 ms |
2780 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
171 ms |
21432 KB |
Output is correct |
2 |
Correct |
172 ms |
21688 KB |
Output is correct |
3 |
Correct |
172 ms |
21692 KB |
Output is correct |
4 |
Correct |
170 ms |
21424 KB |
Output is correct |
5 |
Correct |
163 ms |
20920 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
179 ms |
20920 KB |
Output is correct |
2 |
Correct |
179 ms |
20896 KB |
Output is correct |
3 |
Correct |
179 ms |
20872 KB |
Output is correct |
4 |
Correct |
150 ms |
16328 KB |
Output is correct |
5 |
Correct |
154 ms |
14984 KB |
Output is correct |