Submission #1108921

#TimeUsernameProblemLanguageResultExecution timeMemory
1108921Hora000Global Warming (CEOI18_glo)C++17
0 / 100
86 ms4176 KiB
#include <algorithm> #include <bits/stdc++.h> using namespace std; int main() { int n, x; cin >> n >> x; vector<int> a(n); vector<int> lis, rlis; vector<int> maxlis(n), rmaxlis(n); vector<int> baselis(n), rbaselis(n); for(int i = 0; i < n; i++){ cin >> a[i]; auto it = lower_bound(lis.begin(), lis.end(), a[i]); auto it2 = lower_bound(lis.begin(), lis.end(), a[i] + x); if(it == lis.end()){ lis.push_back(a[i]); maxlis[i] = lis.size(); baselis[i] = lis.size(); } else{ maxlis[i] = it2 - lis.begin(); baselis[i] = it - lis.begin(); *it = a[i]; } } for(int i = n - 1; i >= 0; i--){ auto it = lower_bound(rlis.begin(), rlis.end(), -a[i]); auto it2 = lower_bound(rlis.begin(), rlis.end(), -a[i] - x); if(it == rlis.end()){ rlis.push_back(-a[i]); rmaxlis[i] = rlis.size(); rbaselis[i] = rlis.size(); } else{ rmaxlis[i] = it2 - rlis.begin(); rbaselis[i] = it - rlis.begin(); *it = -a[i]; } } int maxi = 0; for(int i = 0; i < n; i++){ maxi = max(maxi, max(maxlis[i] + rbaselis[i] - 1, baselis[i] + rmaxlis[i] - 1)); } cout << maxi << "\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...