Submission #1090667

#TimeUsernameProblemLanguageResultExecution timeMemory
1090667NurislamGlobal Warming (CEOI18_glo)C++17
100 / 100
50 ms8540 KiB
#include <bits/stdc++.h> using namespace std; #define pb push_back #define ff first #define ss second #define all(x) x.begin(),x.end() #define rall(x) x.rbegin(),x.rend() #define int long long template <class F, class _S> bool chmin(F &u, const _S &v){ bool flag = false; if ( u > v ){ u = v; flag |= true; } return flag; } template <class F, class _S> bool chmax(F &u, const _S &v){ bool flag = false; if ( u < v ){ u = v; flag |= true; } return flag; } const int inf = 1e10, N = 2e5+55; //int mod = 998244353 //int mod = 1000000007; //mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //#define rnd(l, r) uniform_int_distribution <int> (l, r)(rng) void solve(){ int n, x; cin >> n >> x; vector<int> a(n); for(int &i:a)cin >> i; vector<int> lis (n+1, inf); lis[0] = -inf; vector<array<int,2>> at(n+1, {0, -inf}); for(int i = 0; i < n; i++){ int l = upper_bound(all(lis), a[i] - x) - lis.begin(); if (lis[l - 1] < a[i] - x) { lis[l] = a[i] - x; at[i + 1] = {l, a[i] - x}; } } int ans = at[n][0]; lis.assign(n+1, inf); lis[0] = -inf; for(int i = n-1; i >= 0; i--){ int l = upper_bound(all(lis), -a[i]) - lis.begin(); if(lis[l-1] < -a[i]){ lis[l] = -a[i]; } l = lower_bound(all(lis), -at[i][1]) - lis.begin()-1; chmax(ans, at[i][0] + l); } cout << ans << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int tt = 1; //cin >> tt; while(tt--){ 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...