Submission #1203965

#TimeUsernameProblemLanguageResultExecution timeMemory
1203965euclidGlobal Warming (CEOI18_glo)C++20
100 / 100
40 ms4368 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define pb push_back #define fi first #define se second #define vi vector<int> #define pii pair<int, int> #define pll pair<ll, ll> #define vl vector<ll> int n, x; const int MN = 2e5 + 7, INF = 1e9 + 7; int a[MN], f[MN], g[MN], dp1[MN], dp2[MN]; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n >> x; for(int i = 1; i <= n; i++) cin >> a[i]; for(int i = 1; i <= n; i++) dp1[i] = INF, dp2[i] = -INF; for(int i = 1; i <= n; i++) { int j = upper_bound(dp1+1, dp1+1+n, a[i])-dp1; if(a[i] == dp1[j-1]) { f[i] = j-1; continue; } dp1[j] = a[i]; f[i] = j; } for(int i = n; i >= 1; i--) { int j = upper_bound(dp2+1, dp2+1+n, a[i]-x, greater<>())-dp2; if(a[i]-x == dp2[j-1]) g[i] = j-1; else g[i] = j; j = upper_bound(dp2+1, dp2+1+n, a[i], greater<>())-dp2; if(a[i] != dp2[j-1]) dp2[j] = a[i]; } int ans = 0; for(int i = 1; i < n; i++) ans = max(ans, f[i]+g[i]-1); cout << ans << '\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...