이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//khodaya khodet komak kon
#include <bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define all(x) x.begin(), x.end()
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int N = 2000 + 10;
const ll MOD = 1000000000 + 7;
const ll INF = 1000000000000000010;
const ll LOG = 25;
int dp[N][N], n, p, q, a[N];
bool isval(int w){
//cout << w << ' ';
memset(dp, 0, sizeof dp);
for (int i = 0; i <= p; i++) for (int j = 0; j <= q; j++){
int x = dp[i][j];
//cout << i << ' ' << j << ' ' << dp[i][j] << '\n';
x++;
if (dp[i][j] >= n - 1) return 1;
int koj = upper_bound(a + 1, a + n + 1, a[x] + (w - 1)) - a;
dp[i + 1][j] = max(dp[i + 1][j], koj - 1);
koj = upper_bound(a + 1, a + n + 1, a[x] + 2 * w - 1) - a;
dp[i][j + 1] = max(dp[i][j + 1], koj - 1);
}
// cout << dp[p][q] << '\n';
return (dp[p][q] >= n - 1);
}
int32_t main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> p >> q;
for (int i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
n++;
a[n] = INF;
int l = 0, r = 1000000000;
while (r - l > 1){
int md = (l + r) >> 1;
if (isval(md)) r = md;
else l = md;
}
cout << r;
// isval(32);
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |