제출 #601680

#제출 시각아이디문제언어결과실행 시간메모리
601680pakhomoveeGlobal Warming (CEOI18_glo)C++17
100 / 100
63 ms5452 KiB
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <map>

using namespace std;

const int inf = 2e9 + 10;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    for (int& i : a) {
        cin >> i;
    }
    vector<int> p(n + 1, inf);
    for (int& i : a) i = -i;
    p[0] = -inf;
    vector<int> dpp(n, 0);
    vector<int> query(n);
    for (int i = n - 1; i >= 1; --i) {
        int id = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
        if (p[id - 1] < a[i]) {
            p[id] = a[i];
        }
        dpp[i] = id;
    }
    for (int& i : a) i = -i;
    p.assign(n + 1, inf);
    p[0] = -inf;
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        int gt = upper_bound(p.begin(), p.end(), a[i] + x - 1) - p.begin() - 1;
        int id = lower_bound(p.begin(), p.end(), a[i]) - p.begin();
        if (p[id - 1] < a[i]) {
            p[id] = a[i];
        }
        ans = max(ans, dpp[i] + gt);
    }
    cout << ans;
}
#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...