# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1091528 | stdfloat | 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>
using namespace std;
using ll = long long;
#define all(v) (v).begin(), v.end()
int main() {
ios::sync_with_stdio(false); cin.tie(nullptr);
int n, x;
cin >> n >> x;
vector<int> a(n);
for (auto &i : a)
cin >> i;
if (!x) {
vector<int> v;
for (int i = 0; i < n; i++) {
if (v.empty() || v.back() < a[j]) v.push_back(a[j]);
else v[lower_bound(all(v), a[j]) - v.begin()] = a[j];
}
return cout << (int)v.size(), 0;
}
int ans = 0;
vector<int> v1, v2;
for (int i = 0; i < n; i++) {
vector<int> u1 = v1, u2 = v2;
for (int j = i; j < n; j++) {
a[j] += x;
if (u1.empty() || u1.back() < a[j]) u1.push_back(a[j]);
else u1[lower_bound(all(u1), a[j]) - u1.begin()] = a[j];
a[j] -= x;
if (u2.empty() || u2.back() < a[j]) u2.push_back(a[j]);
else u2[lower_bound(all(u2), a[j]) - u2.begin()] = a[j];
}
ans = max({ans, (int)u1.size(), (int)u2.size()});
if (v1.empty() || v1.back() < a[i]) v1.push_back(a[i]);
else v1[lower_bound(all(v1), a[i]) - v1.begin()] = a[i];
a[i] -= x;
if (v2.empty() || v2.back() < a[i]) v2.push_back(a[i]);
else v2[lower_bound(all(v2), a[i]) - v2.begin()] = a[i];
}
cout << ans << '\n';
}