Submission #707930

# Submission time Handle Problem Language Result Execution time Memory
707930 2023-03-10T14:12:10 Z Dan4Life Watching (JOI13_watching) C++17
0 / 100
6 ms 8404 KB
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define int long long
#define sz(a) (int)a.size()
const int mxN = (int)2e3+10;
const int LINF = (int)1e9;
int n, p, q;
deque<pair<int,int>> dq;
int a[mxN], ip[mxN], iq[mxN], dp[mxN][mxN];

bool work(int w){
	dq.clear(), dq.push_back({0,0});
	for(int i = 1, s=0; i <= n; i++){
		s+=a[i]-a[i-1]; dq.push_back({s,i});
		while(s-dq.front().fi+1 > w) dq.pop_front();
		ip[i] = dq.front().se-1;
	}	
	dq.clear(), dq.push_back({0,0});
	for(int i = 1, s=0; i <= n; i++){
		s+=a[i]-a[i-1]; dq.push_back({s,i});
		while(s-dq.front().fi+1 > 2*w) dq.pop_front();
		iq[i] = dq.front().se-1;
	}	
	ip[1]=iq[1]=0;
	for(int i = 0; i <= n; i++)
		for(int j = 0; j <= q; j++)
			dp[i][j]=LINF;
	dp[0][0]=0;
	for(int i = 1; i <= n; i++){
		for(int j = 0; j <= q; j++){
			dp[i][j] = min(dp[i][j], dp[ip[i]][j]+1);
			if(j) dp[i][j] = min(dp[i][j], dp[iq[i]][j-1]);
		}
	}
	for(int i = 0; i <= q; i++) 
		if(dp[n][i]<=p) return true;
	return false;
}

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);
	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;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 712 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 8404 KB Output isn't correct
2 Halted 0 ms 0 KB -