Submission #1164753

#TimeUsernameProblemLanguageResultExecution timeMemory
1164753ReLiceWatching (JOI13_watching)C++20
50 / 100
143 ms327680 KiB
#include <bits/stdc++.h> #define ll long long #define ld double #define pb push_back #define pf push_front #define ins insert #define fr first #define sc second #define endl "\n" #define ar array #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() using namespace std; void start(){ios_base::sync_with_stdio(NULL);cin.tie(nullptr);cout.tie(nullptr);} const ll inf = 1e18; const ll mod = 1e9 + 7; const ll N = 1e5 + 8; void solve() { ll i, j; ll n, p, q; cin>>n>>p>>q; vector<ll> a(n); for(i=0;i<n;i++) cin>>a[i]; sort(all(a)); ll dp[n + 1][p + 1]; if(p + q >= n) { cout<<1<<endl; return; } ll l = 0, r = (a[n - 1] - a[0] + 3) / 3; while(l + 1 < r){ ll m = (l + r) / 2; memset(dp, 0x3f, sizeof(dp)); dp[0][0] = 0; for(i=0;i<n;i++){ for(j=0;j<=p;j++){ if(dp[i][j] > q) continue; if(j < p){ ll low = lower_bound(all(a), a[i] + m) - a.begin(); dp[low][j + 1] = min(dp[low][j + 1], dp[i][j]); } if(dp[i][j] < q){ ll low = lower_bound(all(a), a[i] + m * 2) - a.begin(); dp[low][j] = min(dp[low][j], dp[i][j] + 1); } } } ll mn = inf; for(i=0;i<=p;i++) mn = min(mn, dp[n][i]); if(mn <= q) r = m; else l = m; } cout<<r<<endl; } signed main(){ start(); ll t = 1; //cin>>t; while(t--) solve(); } /* */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...