Submission #952562

#TimeUsernameProblemLanguageResultExecution timeMemory
952562SundavarGlobal Warming (CEOI18_glo)C++14
100 / 100
104 ms5484 KiB
#include <bits/stdc++.h> using namespace std; int main(){ int n,d; cin>>n>>d; vector<int> v(n); for(int& a : v) cin>>a; vector<int> smallest(n+1, 1e9+7), here(n); smallest[0] = 0; for(int i = 0; i < n; i++){ int l = lower_bound(smallest.begin(), smallest.end(), v[i]) - smallest.begin(); here[i] = l; smallest[l] = v[i]; } vector<int> biggest(n+1, -(1e9+7)); biggest[0] = 1e9+7; int sol = 0; for(int i = n-1; i >= 0; i--){ int l = 0, r = n; while(r-l > 1) if(biggest[(r+l)/2] > v[i]-d) l = (l+r)/2; else r = (l+r)/2; sol = max(sol, l+here[i]); l = 0, r = n; while(r-l > 1) if(biggest[(r+l)/2] > v[i]) l = (l+r)/2; else r = (l+r)/2; biggest[l+1] = v[i]; } cout << sol << "\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...