#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define si second
typedef pair<int,int> pi;
#ifdef LOCAL
#define debug(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) 69
#endif
template <typename Arg>
void __f(string name, Arg arg) {
cerr << name << " = " << arg << endl;
}
template <typename Head, typename... Tail>
void __f(string names, Head head, Tail... tail) {
string cur = "";
for (auto ch: names){if(ch==','){break;}else{cur+=ch;}}
string nxt = names.substr(cur.size()+2);
cerr << cur << " = " << head << ", ";
__f(nxt, tail...);
}
int N, ret, cur;
vector<int> v;
vector<pi> events;
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0);
cin >> N;
vector<int> A(N + 1);
for (int i = 1; i <= N; ++i) cin >> A[i];
for (int i = 1; i <= N; ++i) {
if (A[i] != A[i - 1]) {
v.pb(A[i]);
}
}
A.clear();
int n = v.size();
if (n == 1) {
cout << 1;
return 0;
}
for (int i = 1; i < n - 1; ++i) {
if (v[i] > v[i - 1] && v[i] > v[i + 1]) {
events.pb({v[i], 0});
} else if (v[i] < v[i - 1] && v[i] < v[i + 1]) {
events.pb({v[i], 1});
}
}
if (v[0] > v[1]) events.pb({v[0], 0});
if (v[n - 1] > v[n - 2]) events.pb({v[n - 1], 0});
v.clear();
sort(events.begin(), events.end(), greater<pi>());
for (auto i: events) {
if (!i.si) cur += 1;
else cur -= 1;
ret = max(cur, ret);
}
cout << ret;
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
364 KB |
Output is correct |
2 |
Correct |
1 ms |
364 KB |
Output is correct |
3 |
Correct |
1 ms |
364 KB |
Output is correct |
4 |
Correct |
1 ms |
364 KB |
Output is correct |
5 |
Correct |
1 ms |
364 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
13 ms |
3432 KB |
Output is correct |
2 |
Correct |
13 ms |
3432 KB |
Output is correct |
3 |
Correct |
13 ms |
3432 KB |
Output is correct |
4 |
Correct |
13 ms |
3432 KB |
Output is correct |
5 |
Correct |
15 ms |
3432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
20 ms |
4076 KB |
Output is correct |
2 |
Correct |
17 ms |
4076 KB |
Output is correct |
3 |
Correct |
22 ms |
4076 KB |
Output is correct |
4 |
Correct |
24 ms |
4076 KB |
Output is correct |
5 |
Correct |
19 ms |
4076 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
209 ms |
32656 KB |
Output is correct |
2 |
Correct |
210 ms |
32528 KB |
Output is correct |
3 |
Runtime error |
216 ms |
42208 KB |
Memory limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
206 ms |
32608 KB |
Output is correct |
2 |
Correct |
212 ms |
32608 KB |
Output is correct |
3 |
Runtime error |
219 ms |
41308 KB |
Memory limit exceeded |
4 |
Halted |
0 ms |
0 KB |
- |