제출 #481754

#제출 시각아이디문제언어결과실행 시간메모리
481754BackNoobGlobal Warming (CEOI18_glo)C++14
100 / 100
57 ms5332 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define endl '\n' #define mask(i) (1LL << (i)) #define ull unsigned long long #define ld long double using namespace std; const int mxN = 3e5 + 227; const ll inf = 1e9 + 277; const int mod = 1e9 + 7; const ll infll = 1e18 + 7; const int base = 307; const int LOG = 20; template <typename T1, typename T2> bool minimize(T1 &a, T2 b) { if (a > b) {a = b; return true;} return false; } template <typename T1, typename T2> bool maximize(T1 &a, T2 b) { if (a < b) {a = b; return true;} return false; } int n , x; int a[mxN]; int l[mxN]; int main() { ios_base::sync_with_stdio(false); cin.tie(0); //freopen("task.inp" , "r" , stdin); //freopen("task.out" , "w" , stdout); cin >> n >> x; for(int i = 1 ; i <= n ; i++) cin >> a[i]; int res = 0; vector<ll> lis(n , infll); for(int i = 1 ; i <= n ; i++) { int pos = lower_bound(lis.begin() , lis.end() , a[i]) - lis.begin(); l[i] = pos + 1; maximize(res , l[i]); lis[pos] = a[i]; } lis.assign(n , infll); for(int i = n ; i >= 1 ; i--) { int pos = lower_bound(lis.begin() , lis.end() , -(a[i] - x)) - lis.begin(); maximize(res , l[i] + pos); pos = lower_bound(lis.begin() , lis.end() , -a[i]) - lis.begin(); lis[pos] = -a[i]; } cout << res; 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...