algorithm_2024/P1020/P1020.cpp

35 lines
814 B
C++
Raw Normal View History

2024-10-04 13:04:02 +00:00
#include <algorithm>
2024-10-04 12:04:22 +00:00
#include <iostream>
2024-10-04 13:04:02 +00:00
using std::cin, std::cout, std::iostream, std::max, std::for_each_n;
2024-10-04 12:04:22 +00:00
constexpr size_t MAX_N {(size_t)5e4+5};
2024-10-04 13:04:02 +00:00
int arr[MAX_N], len[MAX_N], ans1, ans2{1}, n, last_max;
2024-10-04 12:04:22 +00:00
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
2024-10-04 13:04:02 +00:00
while(cin>>arr[n++]);
for(int i=0;i<n;i++){
for(int j=i-1;j>=0;j--){ //j<i
if(arr[j]>=arr[i] && len[i]<len[j]+1){
len[i] = len[j] + 1;
}
}
2024-10-04 12:04:22 +00:00
}
2024-10-04 13:04:02 +00:00
for_each_n(len,n,[](decltype(*len) e){
ans1 = std::max(ans1,e);
});
last_max = arr[0];
for_each_n(arr+1,n,[](decltype(*arr) e){
if(last_max < e){
ans2++;
last_max = e;
}else{
last_max = e;
}
});
2024-10-04 12:04:22 +00:00
2024-10-04 13:04:02 +00:00
cout<<ans1<<'\n'<<ans2<<'\n';
2024-10-04 12:04:22 +00:00
}