# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1241996 | orzorzorz | Global Warming (CEOI18_glo) | C++20 | 38 ms | 2628 KiB |
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#ifdef debug
#define dbg(...) cerr<<#__VA_ARGS__<<" = ", de(__VA_ARGS__)
template<typename T>
void de(T t) {cerr<<t<<endl;}
template<typename T, typename ...U>
void de(T t, U...u) {cerr<<t<<", ", de(u...);}
#else
#define dbg(...)
#define endl "\n"
#endif
void usaco(string s) {
freopen((s+".in").c_str(), "r", stdin);
freopen((s+".out").c_str(), "w", stdout);
}
int main() {
ios::sync_with_stdio(0); cin.tie(0);
int n, x; cin>>n>>x;
vector<int> t(n);
for(int i=0; i<n; i++) cin>>t[i];
vector<int> ans(n), ans1(n);
vector<int> dp, dp1;
int len=0;
for(int i=0; i<n; i++) {
auto it=lower_bound(all(dp), t[i]);
if(it==dp.end()) {
dp.push_back(t[i]);
} else {
dp[it-dp.begin()]=t[i];
}
ans[i]=dp.size();
len=max(len, ans[i]);
}
for(int i=n-1; i>=0; i--) {
auto it=lower_bound(all(dp1), t[i], greater<int>());
dbg(i, it-dp1.begin(), ans[i]-1);
len=max(len, int(dp1.end()-it)+1+ans[i]);
auto it1=lower_bound(all(dp1), t[i]+x, greater<int>());
if(it1==dp1.end()) {
dp1.push_back(t[i]+x);
} else {
dp1[it1-dp1.begin()]=t[i]+x;
}
}
cout<<len;
return 0;
}
//rating below 2000 must be solved 2700 should be solved orzorzorz
//dp so hard
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |