Submission #1272042

#TimeUsernameProblemLanguageResultExecution timeMemory
1272042pvb.tunglamGlobal Warming (CEOI18_glo)C++20
28 / 100
2095 ms1508 KiB
#include <bits/stdc++.h>
#define hash _hash_
#define left _left_
#define y1 _y1_

using namespace std;
using ll = long long;
const ll MOD = 1e9 + 7;
const ll oo = 8e18;

/*----------- I alone decide my fate! ----------*/
   /* Chiec den ong sao, sao 5 canh tuoi mau */

int N, d, a[200009], dp[1009][2];

void solve() {
	cin >> N >> d;
	for (int i = 1; i <= N; i ++) {
		cin >> a[i];
	}
	int res = 0;
	for (int i = 1; i <= N; i ++) dp[i][0] = dp[i][1] = 1;
	for (int i = 1; i <= N; i ++) {
		for (int j = i - 1; j >= 1; j --) {
			if (a[i] > a[j]) {
				dp[i][1] = max(dp[i][1], dp[j][1] + 1);
				dp[i][0] = max(dp[i][0], dp[j][0] + 1);
			}
			if (a[i] > a[j] - d) dp[i][0] = max(dp[i][0], dp[j][1] + 1);  
		}
		res = max({res, dp[i][0], dp[i][1]});
	}
	
	for (int i = 1; i <= N; i ++) dp[i][0] = dp[i][1] = 1;
	for (int i = 1; i <= N; i ++) {
		for (int j = i - 1; j >= 1; j --) {
			if (a[i] > a[j] - d) {
				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);
				dp[i][0] = max(dp[i][0], dp[j][0] + 1);
			}
		}
		res = max({res, dp[i][0], dp[i][1]});
	}
	cout << res;
}

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);
	solve();
	return 0;
}

/*
  How can you see into my eyes, like open doors?
  Leading you down into my core, where I've become so numb
  Without a soul, my spirit's sleeping somewhere cold
  Until you find it here and bring it back home!
  Wake me up! Wake me up inside
  Cant wake up? Wake me up inside
*/
#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...