제출 #1136102

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

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define f first
#define s second
#define chmin(a, b) a = min(a,b)
#define chmax(a, b) a = max(a,b)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for (int i = 0; i < (a); i++)
#define all(x) x.begin(),x.end()
#define v vector

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

    int n, d; cin >> n >> d;

    v<int> dp, dp2;
    int pos;
    auto doit = [&](v<int>& arr, int a) {
        pos = lower_bound(all(arr),a)-arr.begin();
        if (pos==arr.size()) {arr.pb(a);}
        else {arr[pos] = a;}
    };

    F0R(i,n) {
        int a; cin >> a;
        doit(dp2,a+d);
        doit(dp,a);
        if (pos==dp2.size()) {dp2.pb(dp[pos]);}
        else {chmin(dp2[pos],dp[pos]);}
    }
    
    cout << dp2.size() << '\n';

    /*
    positive d: do suffix
    negative d: do prefix (which is same as positive d on suffix)

    positive d:
    two lis arrays
    one is without adding, one is with
    without adding: do it normally
    with adding: do it normally
    transition: look for a_i+d

    need to prove monotonicity of both arrays
    first array is easy
    second = min a such that lis with additions of length i (monotonic)

    transitions from first to second:
    update first array, test updated val in second array, update second array?
    no
    do better idea
    */
}
#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...