Submission #494173

#TimeUsernameProblemLanguageResultExecution timeMemory
494173radalGlobal Warming (CEOI18_glo)C++14
100 / 100
73 ms5400 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O2") #pragma GCC target("avx2,fma") #define rep(i,l,r) for (int i = l; i < r; i++) #define repr(i,r,l) for (int i = r; i >= l; i--) #define X first #define Y second #define pb push_back #define endl '\n' #define debug(x) cerr << #x << " : " << x << endl; using namespace std; typedef long long ll; typedef pair<int,int> pll; const long long int N = 2e5+20,mod = 1e9+7,inf = 1e9,sq = 400; inline int mkay(int a,int b){ if (a+b >= mod) return a+b-mod; if (a+b < 0) return a+b+mod; return a+b; } inline int poww(int n,int k){ int c = 1; while (k){ if (k&1) c = (1ll*c*n)%mod; n = (1ll*n*n)%mod; k >>= 1; } return c; } int pre[N],dp[N],a[N],suf[N]; int main(){ ios :: sync_with_stdio(0); cin.tie(0); memset(dp,63,sizeof dp); int n,x; cin >> n >> x; rep(i,1,n+1) cin >> a[i]; dp[0] = 0; rep(i,1,n+1){ int ind = lower_bound(dp,dp+n+1,a[i])-dp; pre[i] = ind; dp[ind] = a[i]; } memset(dp,0,sizeof dp); dp[0] = -inf*2-2; int ans = 0; repr(i,n,1){ int ind = lower_bound(dp,dp+n+1,-a[i])-dp; suf[i] = ind; ans = max(ans,suf[i]+pre[i]-1); ind = lower_bound(dp,dp+n+1,-a[i]-x)-dp; dp[ind] = -a[i]-x; } 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...