Submission #384862

#TimeUsernameProblemLanguageResultExecution timeMemory
384862ngpin04Global Warming (CEOI18_glo)C++14
100 / 100
70 ms4716 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 5; int dp[N]; int a[N]; int n,x; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cin >> n >> x; for (int i = 1; i <= n; i++) cin >> a[i]; vector <int> lis(n, 1e9 + 1); for (int i = 1; i <= n; i++) { int j = lower_bound(lis.begin(), lis.end(), a[i]) - lis.begin(); dp[i] = j + 1; lis[j] = a[i]; } lis.assign(n, 1e9 + 1); int ans = 0; for (int i = n; i >= 1; i--) { int j = lower_bound(lis.begin(), lis.end(), -(a[i] - x)) - lis.begin(); int k = lower_bound(lis.begin(), lis.end(), -a[i]) - lis.begin(); ans = max(ans, dp[i] + j); lis[k] = -a[i]; } cout << ans; 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...