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;
#define pb push_back
using ll = long long;
int mod = 1e9 + 7; // 998244353
const int N = 1e5 + 5;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, A, B;
cin >> n >> A >> B;
int a[n];
for (int &x : a)
cin >> x;
sort(a, a + n);
int l = 0, r = a[n - 1] - a[0];
while (l < r)
{
int mid = (l + r) / 2;
int dp[n + 1] = {};
dp[0] = 1;
deque<int> min_q, max_q;
int last_valid_l = 0;
for (int i = 0; i < n; i++)
{
// mustafaoz orz
// https://a...content-available-to-author-only...e.com/problems/neighborhoods/submissions/3a0bf1cf-fde7-0556-fc37-88a20014c78e/detail
while (max_q.size() && i - max_q.back() >= B)
max_q.pop_back();
while (min_q.size() && i - min_q.back() >= B)
min_q.pop_back();
while (max_q.size() && a[max_q.front()] <= a[i])
max_q.pop_front();
while (min_q.size() && a[min_q.front()] >= a[i])
min_q.pop_front();
max_q.push_front(i);
min_q.push_front(i);
while (a[max_q.back()] - a[min_q.back()] > mid)
{
if (max_q.back() == last_valid_l)
max_q.pop_back();
if (min_q.back() == last_valid_l)
min_q.pop_back();
last_valid_l++;
}
dp[i + 1] = dp[i];
if (i + 1 >= A && last_valid_l <= i - A + 1)
{
dp[i + 1] += dp[i - A + 1] - (last_valid_l ? dp[last_valid_l - 1] : 0) > 0;
}
}
if (dp[n] - dp[n - 1])
r = mid;
else
l = mid + 1;
}
cout << l << "\n";
}
# | 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... |