이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
#define f(i,a,b) for(int i = a; i < b; i++)
#define fa(i,a,b) for(int i = a; i >= b; i--)
#define ff first
#define ss second
const int N = 2005;
const ll inf = 1e17 + 100;
int n, p, q, dp[N][N];
int a[N], idw[N], id2w[N];
void go(int w){
queue <pair<int,int>> q1, q2;
f(i,1,n+1){
q1.push({a[i], i}); q2.push({a[i], i});
while(a[i] - q1.front().first > w-1) q1.pop();
idw[i] = q1.front().second;
while(a[i] - q2.front().first > 2*w-1) q2.pop();
id2w[i] = q2.front().second;
}
f(i,1,n+1) f(j,0,n) dp[i][j] = 0;
f(i,1,n+1){
dp[i][0] = dp[id2w[i] - 1][0] + 1;
f(j,1,n){
dp[i][j] = min(dp[idw[i] - 1][j-1], dp[id2w[i] - 1][j] + 1);
}
}
}
int main(){
cin >> n >> p >> q;
set <int> s;
f(i,1,n+1){
int x; cin >> x;
s.insert(x);
}
n = 0;
for(int x: s) a[++n] = x;
int l = 1, r = 1000000000;
while(l < r){
int m = (l+r)>>1;
go(m);
if(p >= n or dp[n][p] <= q) r = m;
else l = m+1;
}
cout << l << "\n";
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |