제출 #390771

#제출 시각아이디문제언어결과실행 시간메모리
390771SirCovidThe19thGlobal Warming (CEOI18_glo)C++14
100 / 100
130 ms5352 KiB
#include <bits/stdc++.h>
using namespace std;

int main() {
	//days, max decrement
    int n, x;
    cin >> n >> x;
    int days[n];
    for (int i = 0; i < n; i++)
        cin >> days[i];
    
    int pref[n];
    int suff[n];

    int dp[n];
    fill(dp, dp+n, 1000000007);
    for (int i = 0; i < n; i++){
        int pos = lower_bound(dp, dp+n, days[i])-dp;
        dp[pos] = days[i];
        pref[i] = pos+1;
    }
    fill(dp, dp+n, 1000000007);
    for (int i = n-1; i >= 0; i--){
        int pos = lower_bound(dp, dp+n, -(days[i]-x))-dp;
        suff[i] = pos+1;
        pos = lower_bound(dp, dp+n, -days[i])-dp;
        dp[pos] = -days[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++){
        ans = max(ans, pref[i]+suff[i]-1);
    }
    cout<<ans<<endl;
}
#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...