Submission #413564

#TimeUsernameProblemLanguageResultExecution timeMemory
413564nkatoGlobal Warming (CEOI18_glo)C++17
100 / 100
66 ms5328 KiB
#include <bits/stdc++.h> using namespace std; const int nax = 2e5+10; int pfx[nax]; void smx(int& a, int b) { a = max(a, b); } int main() { // freopen(".in", "r", stdin); // freopen(".out", "w", stdout); ios_base::sync_with_stdio(0); cin.tie(0); int n, x; cin >> n >> x; vector<int> t(n); for(int i = 0; i < n; i++) cin >> t[i]; int mx = 0; vector<int> dp(n, INT_MAX); for(int i = 0; i < n; i++) { int j = (int) (lower_bound(begin(dp), end(dp), t[i])-begin(dp)); dp[j] = t[i]; pfx[i] = j+1; smx(mx, pfx[i]); } dp = vector<int>(n, INT_MAX); for(int i = n-1; i >= 0; i--) { int pos = (int) (lower_bound(begin(dp), end(dp), -t[i]+x)-begin(dp)); smx(mx, pfx[i]+pos); int j = (int) (lower_bound(begin(dp), end(dp), -t[i])-begin(dp)); dp[j] = -t[i]; } cout << mx << 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...