# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
785506 | makanhulia | Global Warming (CEOI18_glo) | C++17 | 0 ms | 0 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main() {
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n, x; cin >> n >> x;
if(x==0) {
vector<int> a(n); for(int &p : a) cin >> p;
vector<int> dp; int ans=1;
for(int p : a) {
auto it=lower_bound(dp.begin(), dp.end(), p);
if(it==dp.end()) dp.push_back(p);
else *it=p;
}
ans=dp.size();
cout << ans << '\n';
} else if(x<=5 && n<=50000) {
vector<int> a, b;
while(n--) {
int p; cin >> p;
vector<int> tempaa=a;
auto it=lower_bound(tempaa.begin(), tempaa.end(), p);
if(it==tempaa.end()) tempaa.push_back(p);
else *it=p;
vector<int> tempba=b;
it=lower_bound(tempba.begin(), tempba.end(), p);
if(it==tempba.end()) tempba.push_back(p);
else *it=p;
if(tempaa.size()>tempba.size()) a=tempaa;
else a=tempba; p-=x;
it=lower_bound(b.begin(), b.end(), p);
if(it==b.end()) b.push_back(p);
else *it=p;
}
int ans=max((int)a.size(), (int)b.size());
cout << ans << '\n';
} else if(x==(int)1e9) {
int ans=1;
vector<int> a(n), b, pre(n);
for(int &p : a) cin >> p;
b=a; reverse(b.begin(), b.end());
vector<int> dp;
for(int i=0; i<n; i++) {
int l=0, r=dp.size()-1, idx=-1;
while(l<=r) {
int mid=l+r>>1;
if(b[i]>=dp[mid]) r=mid-1, idx=mid;
else l=mid+1;
}
if(idx==-1) dp.push_back(b[i]);
else dp[mid]=b[i];
pre[i]=dp.size();
}
dp.clear();
for(int i=0; i<n; i++) {
auto it=lower_bound(dp.begin(), dp.end(), a[i]);
if(it==dp.end()) dp.push_back(a[i]);
else *it=a[i];
ans=max(ans, (int)dp.size()+pre[n-i-2]);
}
cout << ans << '\n';
} else {
vector<int> a(n); for(int &p : a) cin >> p;
vector<int> dp; int ans=1;
for(int i=0; i<n; i++) {
dp.clear();
vector<int> temp=a;
for(int k=i; k<n; k++) temp[k]+=x;
for(int p : temp) {
auto it=lower_bound(dp.begin(), dp.end(), p);
if(it==dp.end()) dp.push_back(p);
else *it=p;
}
ans=max(ans, (int)dp.size());
}
cout << ans << '\n';
}
return 0;
}