제출 #1356097

#제출 시각아이디문제언어결과실행 시간메모리
1356097fgggGlobal Warming (CEOI18_glo)C++20
28 / 100
2096 ms12756 KiB
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve() {
    ll n, d;
    cin >> n >> d;
    vector<ll> a(n);
    for (ll& x : a) cin >> x;
    vector<vector<ll>> dp(n, vector<ll>(2, 1));
    dp[0][1] = 1;
    dp[0][0] = 1;
    for (ll i = 1; i < n; i++) {
        for (ll j = 0; j < i; j++) {
            if (a[i] > a[j]) dp[i][1] = max(dp[i][1], dp[j][1] + 1);
            if (a[i] > a[j] - d) dp[i][0] = max(dp[i][0], dp[j][1] + 1);
            if (a[i] > a[j]) dp[i][0] = max(dp[i][0], dp[j][0] + 1);
        }
    }
    ll ans = 0;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < dp[i].size(); j++) ans = max(ans, dp[i][j]);
    }
    dp = vector<vector<ll>>(n, vector<ll>(2, 1));
    dp[0][0] = 1;
    dp[0][1] = 1;
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < i; j++) {
            if (a[i] > a[j]) dp[i][0] = max(dp[i][0], dp[j][0] + 1);
            if (a[i] + d > a[j]) dp[i][1] = max(dp[i][1], dp[j][0] + 1);
            if (a[i] > a[j]) dp[i][1] = max(dp[i][1], dp[j][1] + 1);
        }
    }
    for (ll i = 0; i < n; i++) {
        for (ll j = 0; j < dp[i].size(); j++) ans = max(ans, dp[i][j]);
    }
    cout << ans;
}
signed main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    ll 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...
#Verdict Execution timeMemoryGrader output
Fetching results...