# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
140565 | HellAngel | Global Warming (CEOI18_glo) | C++14 | 71 ms | 9336 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;
const int maxn = 2e5 + 7;
int n, x, a[maxn], d[maxn], Max = 0, prf[maxn], suf[maxn], ans, Maxa = 0, b[maxn];
int32_t main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
if(fopen("test.inp", "r")) freopen("test.inp", "r", stdin), freopen("test.out", "w", stdout);
cin >> n >> x;
for(int i = 1; i <= n; i++) cin >> a[i], Maxa = max(Maxa, a[i]);
for(int i = 1; i <= n; i++) b[i] = Maxa - a[i] + 1;
Max = 0;
d[0] = 0;
for(int i = 1; i <= n; i++)
{
int l = 0;
int r = Max;
while(l <= r)
{
int mid = l + r >> 1;
if(a[i] > d[mid]) l = mid + 1;
else r = mid - 1;
}
Max = max(Max, l);
d[l] = a[i];
prf[i] = l;
}
Max = 0;
d[0] = 0;
for(int i = n; i >= 1; i--)
{
int l = 0;
int r = Max;
while(l <= r)
{
int mid = l + r >> 1;
if(b[i] > d[mid]) l = mid + 1;
else r = mid - 1;
}
Max = max(Max, l);
d[l] = b[i];
suf[i] = l;
}
ans = Max;
Max = 0;
d[0] = LLONG_MIN;
for(int i = 1; i < n; i++)
{
d[prf[i]] = a[i] - x;
Max = max(Max, prf[i]);
int l = 0;
int r = Max;
while(l <= r)
{
int mid = l + r >> 1;
if(d[mid] < a[i + 1]) l = mid + 1;
else r = mid - 1;
}
ans = max(ans, suf[i + 1] + r);
}
cout << ans;
}
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... |