This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n, d;
cin >> n >> d;
vector<int>dp(n + 1, 0);
vector<int>suff(n + 2, 0);
vector<int> a(n + 1);
for (int i=1; i<=n; i++)
cin >> a[i];
stack<int>st;
vector<int>nxt(n + 1, 0);
for (int i=n; i>0; i--)
{
while (!st.empty() && a[i] >= a[st.top()])
st.pop();
nxt[i] = (st.empty()? n + 1 : st.top());
st.push(i);
}
for (int i=n; i>0; i--)
{
suff[i] = max(suff[i+1], a[i]);
dp[i] = dp[nxt[i]] + 1;
}
cout << *max_element(dp.begin(), dp.end());
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |