Submission #789184

#TimeUsernameProblemLanguageResultExecution timeMemory
789184boyliguanhanGlobal Warming (CEOI18_glo)C++17
100 / 100
88 ms5080 KiB
#include<bits/stdc++.h> using namespace std; int pre[200100], suf[200100], arr[200100], ans; vector<int> v; int main() { int n, x; cin >> n >> x; for(int i = 0; i < n; i++) { cin >> arr[i]; auto it = lower_bound(v.begin(), v.end(), arr[i]); pre[i] = it-v.begin()+1; if(it==v.end()) v.push_back(arr[i]); else *it = arr[i]; } v.clear(); for(int i = n; i--;) { auto it = lower_bound(v.begin(), v.end(), arr[i], [](int a, int b){return a>b;}); auto i2 = lower_bound(v.begin(), v.end(), arr[i] - x, [](int a, int b){return a>b;}); suf[i] = i2-v.begin()+1; if(it==v.end()) v.push_back(arr[i]); else *it = arr[i]; } for(int i = 0; i < n; i++){ ans = max(ans, pre[i]+suf[i]-1); } cout << ans << '\n'; }
#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...