This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef long long ll;
pair<bool,int> DP[101][101][101];
int arr[101];
int n,p,q;
bool check(int w){
for(auto&i:DP)for(auto&j:i)for(auto&k:j)k={false,0ll};
for(auto&i:DP[0])for(auto&j:i)j.first=true;
for(int i=1;i<=n;i++){
for(int j=0;j<=p;j++){
for(int k=0;k<=q;k++){
if(DP[i-1][j][k].second>=arr[i] and DP[i-1][j][k].first)DP[i][j][k]=DP[i-1][j][k];
if(j!=0 and DP[i-1][j-1][k].first)DP[i][j][k]=max(DP[i][j][k],{true,arr[i]+2*w-1});
if(k!=0 and DP[i-1][j][k-1].first)DP[i][j][k]=max(DP[i][j][k],{true,arr[i]+w-1});
}
}
}
return !DP[n][p][q].first;
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> n >> q >> p;
for(int i=1;i<=n;i++)cin>>arr[i];
if(p+q>=n){
cout << "1\n";
return 0;
}
sort(arr+1,arr+1+n);
int ans = 0;
for(int jump=536870912;jump;jump/=2){
if(check(ans+jump))ans+=jump;
}
ans++;
cout << ans << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |