Submission #481752

#TimeUsernameProblemLanguageResultExecution timeMemory
481752BackNoobGlobal Warming (CEOI18_glo)C++14
15 / 100
34 ms3912 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<int> lis; for(int i = 1 ; i <= n ; i++) { int pos = lower_bound(lis.begin() , lis.end() , a[i]) - lis.begin(); l[i] = pos + 1; if(pos == (int) lis.size()) lis.push_back(a[i]); else lis[pos] = a[i]; maximize(res , l[i]); } lis.clear(); 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(); if(pos == (int) lis.size()) lis.push_back(-a[i]); else l[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...