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 pf printf
#define sf scanf
typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
#define maxn 505
#define INF 1023456789
int n,k,a[maxn],b[maxn];
vector<ii> v;
ld memo[maxn+5][maxn+5][maxn+5];
ld dp(int pos,int ppl,int vote){
if(pos==n){
if(vote>=k)return 0;
else return INF;
}
if(memo[pos][ppl][vote]>=0)return memo[pos][ppl][vote];
ld ans=INF;
//case 1: dont take
ans=min(ans,dp(pos+1,ppl,vote));
//case 2: just get vote
ans=min(ans,dp(pos+1,ppl,vote+1)+(ld)a[pos]/(ppl+1));
//case 3: get new person
if(b[pos]!=INF)ans=min(ans,dp(pos+1,ppl+1,vote+1)+(ld)b[pos]/(ppl+1));
//pf("%d %d %d: %f\n",pos,ppl,vote,ans);
return memo[pos][ppl][vote]=ans;
}
int main(){
sf("%d%d",&n,&k);
for(int i=0;i<n;++i){
int x,y;
sf("%d%d",&x,&y);
if(y==-1)y=INF;
v.push_back({y,x});
}
sort(v.begin(),v.end());
for(int i=0;i<n;++i){
tie(b[i],a[i])=v[i];
}
for(int i=0;i<=n;++i){
for(int j=0;j<=n;++j){
for(int l=0;l<=n;++l){
memo[i][j][l]=-1;
}
}
}
pf("%Lf\n",dp(0,0,0));
}
Compilation message (stderr)
Main.cpp: In function 'int main()':
Main.cpp:35:4: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
35 | sf("%d%d",&n,&k);
| ^
Main.cpp:38:5: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
38 | sf("%d%d",&x,&y);
| ^
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |