提交时间:2024-03-30 16:28:02
运行 ID: 140613
#include<bits/stdc++.h> using namespace std; int n,a[5001],f[5001],g[5001],s1,s2,t1,t2; stack<int>s; string str; char ch; int main() { getline(cin,str); istringstream iss(str); while(iss>>a[++n]) { t1=t2=0,f[n]=g[n]=1; for(int j=1;j<n;j++) { if(a[j]>a[n]&&f[j]>f[t1]) t1=j; if(a[j]<a[n]&&g[j]>g[t2]) t2=j; } f[n]+=f[t1],g[n]+=g[t2],s1=max(s1,f[n]),s2=max(s2,g[n]); } cout<<s1<<' '<<s2; }