이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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... |