Submission #1218754

#TimeUsernameProblemLanguageResultExecution timeMemory
1218754muhammadali_2009Global Warming (CEOI18_glo)C++20
0 / 100
39 ms6080 KiB
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+     //          

#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define ll long long
#define int long long
#define all(x) x.begin(), x.end()
#define all1(x) x.rbegin(), x.rend()
#define seea(x) for(int i = 0; i < x; i++)
#define pb push_back
#define ff first
#define vc vector
#define ss second

using namespace std;  
const int mod = 1e9 + 7;

int lis(vector<int>a){
    int n = a.size();
    vector<int>dp;
    for(int i = 0; i < n; i ++){
        auto id = lower_bound(dp.begin(), dp.end(), a[i]);
        if(id == dp.end()){
            dp.push_back(a[i]);
        }
        else dp[id - dp.begin()] = a[i];
    }
    return dp.size();
}

void solve() {
    int ans = 1;
    int n, x; cin >> n >> x;
    vector<int>a(n), dp;
    seea(n) cin >> a[i];
    //pref[i] -> i-indeksgacha va i ni olgandagi lis
    //suf[i] -> 1 .. i - indeks -x qilingandagi va i - indexdan n - gacha lis
    vector<int>pref(n + 1), suf(n + 2);
    for(int i = 1; i <= n; i ++){
        auto id = lower_bound(dp.begin(), dp.end(), a[i - 1]);
        if(id == dp.end()){
            dp.push_back(a[i - 1]);
        }
        else{
            dp[id - dp.begin()] = a[i - 1];
        }
        pref[i] = dp.size();
        ans = max(ans, pref[i]);
    }
    //cout << ans << endl;
     dp.clear();
    for(int i = n; i >= 1; i--){
        auto id = lower_bound(all(dp), -a[i - 1] + x);
        suf[i] = id - dp.begin();
        auto pos = lower_bound(all(dp), -a[i - 1]);
        if(pos == dp.end()) dp.pb(-a[i - 1]);
        else *pos = -a[i - 1];
    }
    for(int i = 0; i <= n; i++) ans = max(ans, pref[i] + suf[i + 1]);
    cout << ans << endl;
}

signed main(){
    fast;
    int t = 1;
    //cin >> t;
    while (t--){
        solve();
    }
}
#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...