제출 #161195

#제출 시각아이디문제언어결과실행 시간메모리
161195rama_pangGlobal Warming (CEOI18_glo)C++14
27 / 100
73 ms2732 KiB
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9 + 7;

int N, X;
int A[200005];
int last[200005];
int jumped[200005];

int LIS() {
    for (int i = 0; i <= N; i++) last[i] = INF, jumped[i] = INF;
    last[0] = -INF - 100;
    jumped[0] = -INF - 100;

    for (int i = 0; i < N; i++) {
        int j;
        
        j = upper_bound(last, last + N + 1, A[i]) - last;
        if (last[j - 1] < A[i] && A[i] < last[j]) last[j] = A[i];

        j = upper_bound(jumped, jumped + N + 1, A[i]) - jumped;
        if (jumped[j - 1] < A[i] && A[i] < jumped[j]) jumped[j] = A[i];
        
        j = upper_bound(jumped, jumped + N + 1, A[i] - X) - jumped;
        if (jumped[j - 1] < A[i] - X && A[i] - X < jumped[j]) jumped[j] = A[i] - X;

    }

    int res = 0;
    for (int i = 0; i <= N; i++) {
        if (last[i] < INF) res = max(res, i);
        if (jumped[i] < INF) res = max(res, i);
    }

    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);

    cin >> N >> X;
    for (int i = 0; i < N; i++) cin >> A[i];

    int ans = LIS();

    cout << ans << "\n"; 

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