Submission #1051010

#TimeUsernameProblemLanguageResultExecution timeMemory
1051010dpsaveslivesWatching (JOI13_watching)C++17
0 / 100
1 ms348 KiB
#include <bits/stdc++.h> using namespace std; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); int N,P,Q; cin >> N >> P >> Q; vector<int> arr(N); for(int i = 0;i<N;++i) cin >> arr[i]; if(P+Q >= N){ cout << 1 << "\n"; return 0; } sort(arr.begin(),arr.end()); int lo = 0, hi = 1e9; while(lo < hi){ int w = lo+(hi-lo)/2; vector<vector<int>> dp(P+1,vector<int>(Q+1,0)); for(int i = 0;i<=P;++i){ for(int j = 0;j<=Q;++j){ int ind = dp[i][j]; if(i < P){ int it = lower_bound(arr.begin(),arr.end(),arr[ind]+w)-arr.begin(); dp[i+1][j] = max(dp[i+1][j],it); } if(j < Q){ int it2 = lower_bound(arr.begin(),arr.end(),arr[ind]+2*w)-arr.begin(); dp[i][j+1] = max(dp[i][j+1],it2); } } } if(dp[P][Q] >= N){ hi = w; } else{ lo = w+1; } } cout << lo << "\n"; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...