Submission #651600

#TimeUsernameProblemLanguageResultExecution timeMemory
651600Koful123Watching (JOI13_watching)C++17
50 / 100
1081 ms74960 KiB
#include <bits/stdc++.h> using namespace std; #define endl "\n" #define pb push_back #define ff first #define ss second #define mod 1000000007 #define all(x) (x).begin(), (x).end() #define rall(x) (x).rbegin(), (x).rend() int n,p,q; const int N = 2e3 + 5; long long v[N]; vector<vector<vector<bool>>> dp,ok; int get(long long val){ int l = 0,r = n-1; while(l < r){ int m = (l + r) / 2; if(val <= v[m]) r = m; else l = m + 1; } return l + (v[n-1] < val); } bool f(int pos,int p,int q,long long w){ if(p < 0 || q < 0) return false; if(pos == n) return true; if(ok[pos][p][q]) return dp[pos][p][q]; int a = get(v[pos] + w); int b = get(v[pos] + 2*w); dp[pos][p][q] = (f(a,p-1,q,w) || f(b,p,q-1,w)); ok[pos][p][q] = true; return dp[pos][p][q]; } bool check(long long m){ dp.assign(n,vector<vector<bool>>(p+1,vector<bool>(q+1,false))); ok.assign(n,vector<vector<bool>>(p+1,vector<bool>(q+1,false))); return f(0,p,q,m); } void solve(){ cin >> n >> p >> q; for(int i=0;i<n;i++){ cin >> v[i]; } if(p + q >= n){ cout << 1 << endl; return; } sort(v,v+n); int l = 1,r = 1e9; while(l < r){ int m = (l + r) / 2; if(check(m)) r = m; else l = m + 1; } cout << l << endl; } signed main(){ ios::sync_with_stdio(0); cin.tie(0); int t = 1; // cin >> t; while(t--) solve(); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...