제출 #1305816

#제출 시각아이디문제언어결과실행 시간메모리
1305816annnGlobal Warming (CEOI18_glo)C++20
100 / 100
46 ms4444 KiB
#include <bits/stdc++.h>
using namespace std;

#define int long long
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
#define ii pair<int, int>
#define vi vector<int>
#define vii vector<pair<int, int>>
#define yes cout << "YES\n"
#define no cout << "NO\n"
#define mii map<int, int>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define all(a, len) (a) + 1, (a) + len + 1
#define vall(a) (a).begin(), a.end()
const int INF = 4e18;
const int MOD = 1e9 + 7;

int n, x; const int mx = 2e5 + 3;
int a[mx];
int l[mx];
void TheEminemShow() {
    cin >> n >> x;
    rep(i, 1, n) cin >> a[i]; 
}

void Recovery() {
	vi dp;
	rep(i, 1, n) {
		int j = lower_bound(dp.begin(), dp.end(), a[i]) - dp.begin();
		if (j == dp.size()) dp.pb(a[i]);
		else dp[j] = a[i];
		l[i] = j + 1;
	}
	int ans = dp.size();
	
	dp.clear();
	for (int i = n; i >= 1; i--) {
		int j = lower_bound(dp.begin(), dp.end(), - (a[i] - x)) - dp.begin();
		
		ans = max(ans, l[i] + (j + 1) - 1); // tru 1 vi trung vi tri i
		j = lower_bound(dp.begin(), dp.end(), - a[i]) - dp.begin();
		if (j == dp.size()) dp.pb(- a[i]);
		else dp[j] = - a[i];
	}
	cout << ans;
}

void Kamikaze() {

}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);

    int TEST = 1;
    // cin >> TEST;
    while (TEST--) {
        TheEminemShow();
        Recovery();
        Kamikaze();
    }

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