제출 #951676

#제출 시각아이디문제언어결과실행 시간메모리
951676arbuzickFinancial Report (JOI21_financial)C++17
48 / 100
4054 ms10384 KiB
#include <bits/stdc++.h>

using namespace std;

constexpr int inf = 1e9 + 7;

void solve() {
    int n, d;
    cin >> n >> d;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<pair<int, int>> lr(n);
    for (int i = 0; i < n; ++i) {
        lr[i] = {i, i};
        int prv = i;
        for (int j = i - 1; j >= 0; --j) {
            if (a[j] < a[i]) {
                prv = j;
            }
            if (prv - j >= d) {
                break;
            }
            lr[i].first = j;
        }
    }
    vector<pair<int, int>> ord(n);
    for (int i = 0; i < n; ++i) {
        ord[i] = {a[i], -i};
    }
    sort(ord.begin(), ord.end());
    vector<int> dp(n, -inf);
    int ans = 0;
    for (auto [vl, pos] : ord) {
        int i = -pos;
        dp[i] = 1;
        for (int j = lr[i].first; j < lr[i].second; ++j) {
            dp[i] = max(dp[i], dp[j] + 1);
        }
        ans = max(ans, dp[i]);
    }
    cout << ans << '\n';
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int t = 1;
    // cin >> t;
    while (t--) {
        solve();
    }
    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...