Submission #795634

#TimeUsernameProblemLanguageResultExecution timeMemory
795634Trisanu_DasGlobal Warming (CEOI18_glo)C++17
100 / 100
39 ms4668 KiB
#include <bits/stdc++.h> using namespace std; const int N = 2e5 + 1, mod = 1e9 + 7; int n, x, ans = 0, a[N], f[2][N]; int main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> x; for (int i = 1; i <= n; i++) { cin >> a[i]; f[0][i] = f[1][i] = INT_MAX; } f[0][0] = f[1][0] = -INT_MAX; for (int i = 2; i <= n; i++) { int k = lower_bound(f[0] + 1, f[0] + n + 1, a[i - 1] - x) - f[0]; f[0][k] = a[i - 1] - x; f[1][k] = min(f[1][k], f[0][k]); ans = max(ans, k); k = lower_bound(f[1] + 1, f[1] + n + 1, a[i]) - f[1]; f[1][k] = a[i]; ans = max(ans, k); } 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...