Submission #891278

#TimeUsernameProblemLanguageResultExecution timeMemory
891278loliconFinancial Report (JOI21_financial)C++14
48 / 100
4040 ms8528 KiB
#include <bits/stdc++.h>
using namespace std;

const int maxn = 3e5 + 5;

vector<int> V;
int A[maxn];
int n, D;

void nndp() {
    vector<int> dp(n + 1), r(n + 1);
    for(int i = 1; i <= n; ++i) {
        int lst = i;
        for(int j = i; j <= n; ++j) {
            if(j - lst > D) break;
            if(A[j] <= A[i]) lst = j;
        }
        r[i] = lst + D;
    }
    // O(n^2) dp
    for(int i = 1; i <= n; ++i) {
        dp[i] = 1;
        for(int j = 1; j < i; ++j) {
            if(r[j] >= i && A[j] < A[i]) 
                dp[i] = max(dp[i], dp[j] + 1);
        }
    }
    cout << *max_element(begin(dp), end(dp)) << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n >> D;
    for(int i = 1; i <= n; ++i) {
        cin >> A[i]; V.push_back(A[i]);
    }
    sort(begin(V), end(V));
    for(int i = 1; i <= n; ++i) {
        A[i] = lower_bound(begin(V), end(V), A[i]) - begin(V) + 1;
    }
    nndp();
    return 0;
}
#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...