Submission #709862

#TimeUsernameProblemLanguageResultExecution timeMemory
709862MinaRagy06Global Warming (CEOI18_glo)C++17
28 / 100
2062 ms4952 KiB
#include <bits/stdc++.h>
using namespace std;
#define lesgooo ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl    '\n'
#define int     long long

signed main()
{
    lesgooo;
    int n, x;
    cin >> n >> x;
    int a[n];
    for (int i = 0; i < n; i++) cin >> a[i];
    int dp[n][2]{};
    for (int i = n-1; i >= 0; i--) for (int j = 0; j < 2; j++)
    {
        for (int k = i + 1; k < n; k++) if (a[i] < a[k]) dp[i][j] = max(dp[i][j], dp[k][j]);
        if (!j) for (int k = i + 1; k < n; k++) if (a[i]+1-a[k] <= x && -a[i]-1+a[k] <= x) dp[i][j] = max(dp[i][j], dp[k][1]);
        dp[i][j]++;
    }
    int mx = 0;
    for (int i = 0; i < n; i++) mx = max(mx, dp[i][0]);
    cout << mx;
    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...