제출 #1327499

#제출 시각아이디문제언어결과실행 시간메모리
1327499mehralii구경하기 (JOI13_watching)C++20
50 / 100
1095 ms31916 KiB
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>

#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math")
#pragma GCC target("avx2,fma")

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 = 100005;

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

bool ok(int w){
    int mx = min(q, n);
    vector<vector<int>> dp(n+1, vector<int>(mx+1, inf));
    
    for (int cnt = 0; cnt <= mx; ++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 <= mx; ++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 <= mx; 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 = a.back()-a[0]+1, 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...