이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e3+10;
int num[MAXN], n, a, b;
bool ok(int w)
{
int p = a, q = b;
for (int i = 1; i <= n; i++)
{
if (!p && !q) return false;
int pos = n, pos2 = n;
for (int j = i+1; j <= n; j++)
{
if (num[i]+2*w-1 < num[j])
{
pos = j-1;
break;
}
}
if (!p)
{
i = pos;
q--;
continue;
}
for (int j = i+1; j <= n; j++)
{
if (num[i]+w-1 < num[j])
{
pos2 = j-1;
break;
}
}
if (!q)
{
i = pos2;
p--;
continue;
}
if (pos > pos2)
{
q--;
i = pos;
}
else
{
p--;
i = pos2;
}
}
return true;
}
int busca(void)
{
int ini = 1, fim = 1e9+10;
while (ini < fim)
{
int mid = (ini+fim)/2;
if (ok(mid)) fim = mid;
else ini = mid+1;
}
return fim;
}
int main(void)
{
cin >> n >> a >> b;
for (int i = 1; i <= n; i++) cin >> num[i];
sort(num+1, num+n+1);
cout << busca() << "\n";
}
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |
| # | Verdict | Execution time | Memory | Grader output |
|---|
| Fetching results... |