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 int long long
#define pi pair <int, int>
#define ppi pair <pi, int>
#define pb push_back
#define fi first
#define se second
#define all(x) x.begin(), x.end()
using namespace std;
const int inf = 1000000000;
int n, a[1000005], prefmax[1000005], prefmin[1000005];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
cin >> n;
prefmin[0] = inf;
for(int i = 1; i <= n; i++){
cin >> a[i];
prefmax[i] = max(prefmax[i-1], a[i]);
prefmin[i] = min(prefmin[i-1], a[i]);
}
int ans = 1;
int l = 1;
for(int i = 2; i <= n; i++){
if(ans == 1 and a[i] < a[i-1]){
ans++;
//for(int j = l; j < i; j++) cout << a[j] << ' ';
//cout << '\n';
//l = i;
}
else if(ans != 1 and (a[i] < a[i-1] or a[i] < prefmin[i-1] or a[i] > prefmax[i-1])){
ans++;
//for(int j = l; j < i; j++) cout << a[j] << ' ';
//cout << '\n';
//l = i;
}
}
cout << ans;
}
Compilation message (stderr)
money.cpp: In function 'int main()':
money.cpp:22:6: warning: unused variable 'l' [-Wunused-variable]
22 | int l = 1;
| ^
# | 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... |