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<int,int> DP[2001][2001];
int arr[101];
int n,p,q;
bool check(int w){
for(auto&i:DP)for(auto&j:i)j={-1e15,0ll};
for(auto&i:DP[0])i.first=0;
for(int i=1;i<=n;i++){
for(int j=0;j<=q;j++){
if(DP[i-1][j].second>=arr[i])DP[i][j]=DP[i-1][j];
if(j!=0)DP[i][j]=max(DP[i][j],{DP[i-1][j-1].first,arr[i]+w-1});
DP[i][j]=max(DP[i][j],{DP[i-1][j].first-1,arr[i]+2*w-1});
}
}
return -DP[n][q].first > p;
}
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... |