이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
const int mxN = (int)2e3+10;
const int LINF = (int)1e9;
int n, p, q;
int a[mxN], P[mxN], Q[mxN], v[mxN], dp[mxN][mxN];
bool work(int w){
for(int i=2,j=1,k=1; i <= n; i++){
v[i]=v[i-1]+a[i]-a[i-1];
P[i]=upper_bound(v+1,v+i+1,v[i]-w)-begin(v)-1,
Q[i]=upper_bound(v+1,v+i+1,v[i]-2*w)-begin(v)-1;
}
for(int i = 1; i <= n; i++){
for(int j = 0; j <= q; j++){
dp[i][j] = min(LINF, dp[P[i]][j]+1);
if(j) dp[i][j] = min(dp[i][j], dp[Q[i]][j-1]);
}
}
return dp[n][q]<=p;
}
int32_t main() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n >> p >> q;
for(int i = 1; i <= n; i++) cin >> a[i];
sort(a+1,a+n+1); v[1]=a[1];
if(p+q>=n){cout<<1;return 0;}
int l = 1, r = (int)1e9;
while(l<r){
int mid = (l+r)/2;
if(work(mid)) r=mid;
else l=mid+1;
}
cout << l;
}
컴파일 시 표준 에러 (stderr) 메시지
watching.cpp: In function 'bool work(int)':
watching.cpp:13:14: warning: unused variable 'j' [-Wunused-variable]
13 | for(int i=2,j=1,k=1; i <= n; i++){
| ^
watching.cpp:13:18: warning: unused variable 'k' [-Wunused-variable]
13 | for(int i=2,j=1,k=1; i <= n; i++){
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |