제출 #358637

#제출 시각아이디문제언어결과실행 시간메모리
358637sumit_kk10Global Warming (CEOI18_glo)C++14
10 / 100
56 ms3180 KiB
#include <bits/stdc++.h> #define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL) #define ll long long int #define ld long double using namespace std; const int N = 1e6 + 5; const int MOD = 1e9 + 7; int main(){ fast; long long int n, x; cin >> n >> x; vector<int> a(n); for(int i = 0; i < n; ++i) cin >> a[i]; int left_dp[n + 1], right_dp[n + 1]; vector<int> lis; left_dp[0] = 1; lis.push_back(a[0]); for(int i = 1; i < n; ++i){ if(a[i] > lis.back()){ lis.push_back(a[i]); left_dp[i] = lis.size(); } else{ int low = 0, high = lis.size() - 1, ans = -1; while(low <= high){ int mid = (low + high) / 2; if(lis[mid] >= a[i]){ ans = mid; high = mid - 1; } else low = mid + 1; } if(ans != -1) lis[ans] = a[i]; left_dp[i] = ans + 1; } } right_dp[n - 1] = 1; lis.clear(); lis.push_back(a[n - 1]); for(int i = n - 2; i >= 0; --i){ if(a[i] - x < lis.back()) right_dp[i] = lis.size() + 1; if(a[i] < lis.back()) lis.push_back(a[i]); else{ int low = 0, ans = -1, high = lis.size(); while(low <= high){ int mid = (low + high) / 2; if(lis[mid] <= a[i] - x){ ans = mid; high = mid - 1; } else low = mid + 1; } right_dp[i] = ans + 1; low = 0, ans = -1, high = lis.size(); while(low <= high){ int mid = (low + high) / 2; if(lis[mid] <= a[i]){ ans = mid; high = mid - 1; } else low = mid + 1; } if(ans != -1) lis[ans] = a[i]; } } int mx = 0; for(int i = 0; i < n; ++i) mx = max(mx, left_dp[i] + right_dp[i] - 1); cout << mx << '\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...