Submission #1108925

#TimeUsernameProblemLanguageResultExecution timeMemory
1108925Hora000Global Warming (CEOI18_glo)C++14
100 / 100
89 ms7360 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() - 1; baselis[i] = lis.size() - 1; } 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() - 1; rbaselis[i] = rlis.size() - 1; } 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], baselis[i] + rmaxlis[i])); } cout << maxi + 1; }
#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...