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 <iostream>
using namespace std;
int n, d;
int nums[300010];
int dp[300010];
int maxim[300000];
int maxi;
int main(){
cin >> n >> d;
for (int i = 0; i < n; ++i){
cin >> nums[i];
dp[i] = 1;
maxim[i] = 0;
}
maxim[1] = nums[n-1];
for (int i = n-2; i >= 0; --i){
if (nums[i] < nums[i+1]){
dp[i] = dp[i+1]+1;
while (nums[i] < maxim[dp[i]]){
dp[i]++;
}
maxim[dp[i]] = max(maxim[dp[i]], nums[i]);
}
if (nums[i] == nums[i-1]){
dp[i] = dp[i-1];
}
if (nums[i] > nums[i+1]){
while(nums[i] < maxim[dp[i]]){
dp[i]++;
}
maxim[dp[i]] = max(maxim[dp[i]], nums[i]);
}
}
for (int i = 0; i < n; ++i){
maxi = max(maxi, dp[i]);
}
cout << maxi;
}
# | 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... |