Submission #887064

#TimeUsernameProblemLanguageResultExecution timeMemory
887064dsyzGlobal Warming (CEOI18_glo)C++17
100 / 100
54 ms8620 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define MAXN (1000005) int main() { ios_base::sync_with_stdio(false);cin.tie(0); ll N,X; cin>>N>>X; ll arr[N]; for(ll i = 0;i < N;i++){ cin>>arr[i]; } //we can prove that it is always optimal to subtract x from prefix [0,i] because obviously we want the first few elements as small as possible, it will do no worse than subtracting x from [j,i] //since we are subtracting from the prefix, we should obviously subtract as much as possible which is x vector<ll> v(N,1e18); ll longestprefix[N]; ll ans = 0; for(ll i = 0;i < N;i++){ auto it = lower_bound(v.begin(),v.end(),arr[i]); v[it - v.begin()] = arr[i]; longestprefix[i] = it - v.begin() + 1; ans = max(ans,longestprefix[i]); } v.clear(); v = vector<ll>(N, 1e18); for(ll i = N - 1;i >= 0;i--){ ll pos = lower_bound(v.begin(),v.end(),-arr[i] + X) - v.begin(); ans = max(ans,longestprefix[i] + pos); ll insert_pos = lower_bound(v.begin(),v.end(),-arr[i]) - v.begin(); v[insert_pos] = -arr[i]; } 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...