Submission #1271579

#TimeUsernameProblemLanguageResultExecution timeMemory
1271579KALARRYFinancial Report (JOI21_financial)C++20
0 / 100
4094 ms5484 KiB
//chockolateman

#include<bits/stdc++.h>

using namespace std;

int N,D,a[300005],dp[300005],l[300005];

int main()
{
    scanf("%d%d",&N,&D);
    for(int i = 1 ; i <= N ; i++)
        scanf("%d",&a[i]);
    stack<pair<int,int>> ord;
    a[0] = -1;
    ord.push({-1,0});
    for(int i = 1 ; i <= N ; i++)
    {
        while(ord.top().first > a[i])
            ord.pop();
        l[i] = ord.top().second;
        ord.push({a[i],i});
    }
    int ans = 0;
    for(int i = 1 ; i <= N ; i++)
    {
        dp[i] = 1;
        int pos = i;
        while(pos - l[pos] <= D && l[pos] > 0)
        {
            pos = l[pos];
            if(a[pos] < a[i])
                dp[i] = max(dp[i],dp[pos] + 1);
        }
        ans = max(ans,dp[i]);
    }
    printf("%d\n",ans);
    return 0;
}

Compilation message (stderr)

Main.cpp: In function 'int main()':
Main.cpp:11:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |     scanf("%d%d",&N,&D);
      |     ~~~~~^~~~~~~~~~~~~~
Main.cpp:13:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |         scanf("%d",&a[i]);
      |         ~~~~~^~~~~~~~~~~~
#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...