#include <bits/stdc++.h>
#define in freopen("input.txt", "r" ,stdin)
#define out freopen("output.txt", "w" , stdout)
#define ll long long
#define inf 200005
#define fr first
#define sc second
#define pb push_back
#define p_b pop_back
#define mp make_pair
using namespace std;
int n;
int a[1000005];
int main (){
//in;out;
ios_base::sync_with_stdio(0);
cin >> n;
for (int i = 1; i <= n; i++){
cin >> a[i];
}
int maxx = 0;
int minn = 1e6+10;
a[0] = 0;
minn = a[1];
int ind = 1;
for (int i = 1; i <=n; i++){
if (a[i] >= a[i-1]) {
ind = i;
maxx = a[i];
}
else break;
}
int cnt = 1;
for (int i = ind+1 ; i <= n; i++) {
if (a[i] >= maxx){
while (a[i] >= maxx){
maxx = a[i];
i++;
}
cnt++;
}
if (i > n) break;
if (a[i]>= minn){
while (a[i] <= maxx and a[i] <= a[i+1]){
i++;
}
if (a[i] <= maxx)i++;
cnt++;
}
if (i > n) break;
if (a[i] < minn){
int t = a[i];
while (a[i] <= minn and a[i] <= a[i+1]){
i++;
}
minn = t;
if (a[i] <= minn) i++;
cnt++;
}
}
cout << cnt ;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Incorrect |
2 ms |
376 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |