# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
710095 |
2023-03-15T04:35:34 Z |
hpesoj |
Money (IZhO17_money) |
C++17 |
|
1 ms |
340 KB |
#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
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 |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |