Submission #653707

#TimeUsernameProblemLanguageResultExecution timeMemory
653707PagodePaivaGlobal Warming (CEOI18_glo)C++14
28 / 100
2079 ms4204 KiB
#include<bits/stdc++.h>
#define int long long 
#define ms(v) memset(v, -1, sizeof v)
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define all(x) x.begin(), x.end()
#define INF (int) 1e15
#define mp make_pair
#define itn int
#define N 200010

using namespace std;

int n, x;
int v[N];
int dp[N][2];

int32_t main(){
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> x;

    for(int i = 1;i <= n;i++){
        cin >> v[i];
    }

    dp[0][0] = 0;
    dp[0][1] = 0;

    for(int i = 1;i <= n;i++){
        dp[i][0] = 1;
        dp[i][1] = 1;
        for(int j = 1;j < i;j++){
            dp[i][0] = max(dp[i][0], (v[i] > v[j] ? dp[j][0] + 1 : -INF));
            dp[i][1] = max(dp[i][1], max((v[i] > v[j] - x ? dp[j][0] + 1 : -INF), (v[i] > v[j] ? dp[j][1] + 1 : -INF)));
        }
    }

    int res = 0;

    for(int i = 1;i <= n;i++){
        res = max(dp[i][1], res);   
    }

    cout << res << "\n";

    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...