Submission #1130780

#TimeUsernameProblemLanguageResultExecution timeMemory
1130780minggaGlobal Warming (CEOI18_glo)C++17
100 / 100
48 ms5824 KiB
#include "bits/stdc++.h" using namespace std; #define ln "\n" #define pb push_back #define fi first #define se second #define all(x) (x).begin(), (x).end() #define sz(x) ((int)(x).size()) #define int long long const int MOD = 1e9 + 7; const int inf = 2e18; const int N = 2e5 + 7; int n, x, a[N], f[N]; signed main() { cin.tie(0) -> sync_with_stdio(0); cin >> n >> x; for(int i = 1; i <= n; i++) cin >> a[i]; vector<int> vec; int ans = 0; for(int i = 1; i <= n; i++) { int len = lower_bound(all(vec), a[i]) - vec.begin(); f[i] = len + 1; if(len < sz(vec)) { vec[len] = a[i]; } else vec.pb(a[i]); ans = max(ans, f[i]); } vector<int> vec2; for(int i = n; i > 0; i--) { int len = lower_bound(all(vec2), -a[i] + x) - vec2.begin(); ans = max(ans, len + f[i]); int pos = lower_bound(all(vec2), -a[i]) - vec2.begin(); if(pos < sz(vec2)) vec2[pos] = -a[i]; else vec2.pb(-a[i]); } cout << ans << ln; cerr << "\nTime: " << clock() * 1000 / CLOCKS_PER_SEC; }
#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...