Submission #1327481

#TimeUsernameProblemLanguageResultExecution timeMemory
1327481mehraliiWatching (JOI13_watching)C++20
0 / 100
1094 ms327680 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

using namespace std;
// using namespace __gnu_pbds;

// template <typename T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define int long long
#define pb push_back
#define eb emplace_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define ins insert
#define ff first
#define ss second

// mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

constexpr int inf = 1e9+10, mod = 1e9+7, maxn = 300005;

int n, p, q;
vector<int> a;

bool ok(int w){
	vector<vector<int>> dp(n+1, vector<int>(q+1, inf));

	for (int cnt = 0; cnt <= q; cnt++){
		dp[0][cnt] = 0;
	}

	int l1 = 1, l2 = 1;

	for (int i = 1; i <= n; i++){
		while (l1 <= i && a[i]-a[l1]+1 > w+w){
			l1++;
		}
		while (l2 <= i && a[i]-a[l2]+1 > w){
			l2++;
		}
		
		for (int cnt = 0; cnt <= q; cnt++){
			dp[i][cnt] = min(dp[i][cnt], dp[l2 - 1][cnt] + 1);
			if (cnt > 0) {
			    dp[i][cnt] = min(dp[i][cnt], dp[l1 - 1][cnt - 1]);
			}
		}
	}

	for (int cnt = 0; cnt <= q; cnt++){
		if (dp[n][cnt] <= p){
			return true;
		}
	}	

	return false;
}

void solve(){
	cin >> n >> p >> q;
	a.assign(n+1, 0);
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}

	sort(a.begin(), a.end());

	int l = 0, r = 1e10, m;
	while (r-l>1){
		m = l+(r-l)/2;
		if (ok(m)){
			r = m;
		} else{
			l = m;
		}
	}

	cout << r << '\n';
}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
    // cin >> t;

    for (int i = 0; i < t; i++) {
        solve();
    }

    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...