# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
952798 | stakaman | Swimming competition (LMIO18_plaukimo_varzybos) | C++17 | 360 ms | 16212 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;
const int N = 1000006;
int n, a, b;
int u[N];
int p[N];
bool dp[N];
bool solve(int x){
dp[0] = true;
p[0] = 1;
int j = 1;
for (int i = 1; i <= n; ++i) {
p[i] = p[i - 1];
dp[i] = false;
while ((u[i] - u[j] > x))
++j;
if (i - a < 0)
continue;
if (j - 1 <= i - b)
{
if (i - b - 1 < 0)
dp[i] = true;
else if (p[i - a] - p[i - b - 1] > 0)
dp[i] = true;
}
else
{
if (j - 1 <= i - a)
{
if (p[i - a] - p[j - 1 - 1] > 0)
dp[i] = true;
}
}
if (dp[i])
++p[i];
}
return dp[n];
}
int main(){
scanf("%d%d%d", &n, &a, &b);
for (int i = 1; i <= n; ++i)
scanf("%d", &u[i]);
sort(u + 1, u + n + 1);
int l = 0, r = N;
int ans;
while (l <= r) {
int m = (l + r) / 2;
if (solve(m)){
ans = m;
r = m - 1;
}
else
l = m + 1;
}
printf("%d\n", ans);
return 0;
}
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... |