#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
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 |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
457 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
457 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
632 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
632 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
632 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
596 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Runtime error |
471 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Runtime error |
457 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |