제출 #1267404

#제출 시각아이디문제언어결과실행 시간메모리
1267404nekolieGlobal Warming (CEOI18_glo)C++20
100 / 100
43 ms2888 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int n,x; cin >> n >> x; int a[n], lis[n]; vector<int> dp; for (int i = 0; i < n; i++) { cin >> a[i]; if (dp.empty() || a[i]+x > dp.back()) lis[i] = dp.size(); else lis[i] = (lower_bound(dp.begin(),dp.end(),a[i]+x)-dp.begin()); if (dp.empty() || a[i] > dp.back()) dp.push_back(a[i]); else *lower_bound(dp.begin(),dp.end(),a[i]) = a[i]; } dp.clear(); for (int i = n-1; i >= 0; i--) { if (dp.empty() || -a[i] > dp.back()) dp.push_back(-a[i]), lis[i] += dp.size(); else *lower_bound(dp.begin(),dp.end(),-a[i]) = -a[i], lis[i] += (lower_bound(dp.begin(),dp.end(),-a[i])-dp.begin())+1; } cout << *max_element(lis,lis+n) << endl; 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...