제출 #397803

#제출 시각아이디문제언어결과실행 시간메모리
397803iANikzadGlobal Warming (CEOI18_glo)C++14
0 / 100
64 ms8740 KiB
#include<bits/stdc++.h> using namespace std; #define pb push_back #define F first #define S second #define debug(x) cerr<<#x<<" :"<<x<<"\n" #define all(x) x.begin(),x.end() #define pii pair<int,int> #define FAST ios_base::sync_with_stdio(false), cin.tie(), cout.tie(); #define int long long typedef long long ll; typedef long double ld; const int maxn = 5e5 + 7; const int mod = 1e9 + 7; const int INF = 1e9 + 7; const int mlog = 20; const int SQ = 400; int a[maxn]; int L[maxn], R[maxn]; int dp[maxn], pd[maxn]; int32_t main() { FAST; int n, x; cin >> n >> x; for(int i = 1; i <= n; i++) cin >> a[i], dp[i] = pd[i] = +INF; for(int i = 1; i <= n; i++) { int pos = lower_bound(dp + 1, dp + 1 + n, a[i]) - dp; L[i] = pos + 1; dp[pos] = a[i]; } for(int i = n; i > 0; i--) { int pos = lower_bound(pd + 1, pd + 1 + n, -a[i] + x) - pd; R[i] = pos + 1; int npos = lower_bound(pd + 1,pd + 1 + n, -a[i]) - pd; dp[npos] = -a[i]; } int ans = 0; for(int i = 1; i <= n; i++) ans = max(ans, R[i] + L[i] - 1); cout << ans << "\n"; return 0; }
#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...