algorithm_2024/P1020/P1020.cpp
2024-10-04 21:17:44 +08:00

32 lines
768 B
C++

#include <algorithm>
#include <iostream>
using std::cin, std::cout, std::iostream, std::max, std::for_each_n;
constexpr size_t MAX_N {(size_t)5e5+5};
int arr[MAX_N], len[MAX_N], ans1, ans2{1}, n, last_max;
int main(){
iostream::sync_with_stdio(false), cin.tie(0), cout.tie(0);
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;
}
}
}
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;
});
cout<<ans1<<'\n'<<ans2<<'\n';
}