Submission #99621

#TimeUsernameProblemLanguageResultExecution timeMemory
99621AnaiGlobal Warming (CEOI18_glo)C++14
0 / 100
60 ms4344 KiB
#include <bits/stdc++.h> using namespace std; using i64 = long long; const int N = 2e5 + 5; i64 v[N]; int dr[N]; vector<i64> stk; i64 k; int ant, n; int main() { #ifdef HOME freopen("glo.in", "r", stdin); freopen("glo.out", "w", stdout); #endif ios::sync_with_stdio(false); cin.tie(0), cout.tie(0); cin >> n >> k; for (int i = 1; i <= n; ++i) cin >> v[i]; if (n == 1) { cout << "1\n"; return 0; } for (int i = n; i >= 1; --i) { auto it = lower_bound(begin(stk), end(stk), -v[i]); dr[i] = it - begin(stk) + 1; if (it == end(stk)) stk.push_back(-v[i]); else *it = -v[i]; } stk.clear(); for (int i = 1; i < n; ++i) { auto it = lower_bound(begin(stk), end(stk), v[i + 1]); dr[i] = it - begin(stk) + 1; if (it == end(stk)) stk.push_back(v[i]); else *it = v[i]; it = lower_bound(begin(stk), end(stk), v[i + 1] + k); ant = max(ant, dr[i + 1] + int(it - begin(stk))); } cout << ant << 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...