제출 #771152

#제출 시각아이디문제언어결과실행 시간메모리
771152gagik_2007Financial Report (JOI21_financial)C++17
48 / 100
141 ms3572 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; typedef pair<int, int> pii; typedef pair<ll, ll> pll; ll ttt; const ll INF=1e18; const ll MOD=1e9+7; const ll N=2e5+7; ll n,m,k; ll a[N]; ll dp[N]; int ri[N]; void precalc() { } int main() { precalc(); cin>>n>>k; for(int i=0;i<n;i++){ cin>>a[i]; } if(k==1){ stack<int>st; ll ans=0; for(int i=n-1;i>=0;i--){ while(!st.empty()&&st.top()<=a[i]){ st.pop(); } st.push(a[i]); ans=max(ans,(ll)st.size()); } cout<<ans<<endl; return 0; } for(int i=0;i<n;i++){ ri[i]=i; for(int j=i+1;j<min(n,ri[i]+k+1);j++){ if(a[j]<=a[i]){ ri[i]=j; } } //cout<<ri[i]<<" "; } //cout<<endl; ll ans=0; for(int i=0;i<n;i++){ dp[i]=1; for(int j=0;j<i;j++){ if(a[i]>a[j]&&ri[j]>=i-k){ dp[i]=max(dp[i],dp[j]+1); } } if(ri[i]==n-1){ ans=max(ans,dp[i]); } //cout<<dp[i]<<" "; } cout<<ans<<endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...