#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double,double> dd;
const int MAX=1e9;
bool orden(dd a,dd b){
if(a.second==b.second) return a.first<b.first;
return a.second<b.second;
}
int n;
vector<dd> st;
double ka;
double dp[510][510][510];
double knap(int id,int k,int ca){
if(dp[id][k][ca]!=-1) return dp[id][k][ca];
if(id==n) {
if(ca==0 && k==ka) return 0;
return MAX;
}
double ans=knap(id+1,k,ca);
if(ca!=0){
ans=min(ans,knap(id+1,k,ca-1)+st[id].first/(ka+1));
if(k!=ka)
ans=min(ans,knap(id+1,k+1,ca-1)+st[id].second/(double)(k+1));
}
return dp[id][k][ca]=ans;
}
int main(){
int k; scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
int a,b; scanf("%d%d",&a,&b);
if(b==-1) b=MAX;
st.push_back(dd(a,b));
}
sort(st.begin(),st.end(),orden);
double res=MAX;
for(int i=0;i<k;i++){
ka=i;
for(int id=0;id<=n;id++) for(int kk=0;kk<=n;kk++) for(int ca=0;ca<=n;ca++) dp[id][kk][ca]=-1;
double rp=knap(0,0,k);
//cout<<i<<": "<<rp<<endl;
res=min(res,rp);
}
printf("%.15f\n",res);
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:29:15: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
29 | int k; scanf("%d%d",&n,&k);
| ~~~~~^~~~~~~~~~~~~~
Main.cpp:31:19: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
31 | int a,b; scanf("%d%d",&a,&b);
| ~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
276 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
2625 ms |
1004316 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
276 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
2625 ms |
1004316 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
564 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
568 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
568 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
544 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
564 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
568 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
568 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
544 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
2132 KB |
Output is correct |
17 |
Correct |
1 ms |
2132 KB |
Output is correct |
18 |
Correct |
1 ms |
2132 KB |
Output is correct |
19 |
Correct |
2 ms |
2132 KB |
Output is correct |
20 |
Correct |
2 ms |
2132 KB |
Output is correct |
21 |
Correct |
1 ms |
2108 KB |
Output is correct |
22 |
Correct |
2 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
2 ms |
2132 KB |
Output is correct |
25 |
Correct |
2 ms |
2132 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
2 ms |
2132 KB |
Output is correct |
28 |
Correct |
1 ms |
2132 KB |
Output is correct |
29 |
Correct |
2 ms |
2132 KB |
Output is correct |
30 |
Correct |
2 ms |
2132 KB |
Output is correct |
31 |
Correct |
2 ms |
2132 KB |
Output is correct |
32 |
Correct |
2 ms |
2132 KB |
Output is correct |
33 |
Correct |
2 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
2132 KB |
Output is correct |
35 |
Correct |
2 ms |
2132 KB |
Output is correct |
36 |
Correct |
1 ms |
2132 KB |
Output is correct |
37 |
Correct |
2 ms |
2132 KB |
Output is correct |
38 |
Correct |
2 ms |
2104 KB |
Output is correct |
39 |
Correct |
2 ms |
2132 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
468 KB |
Output is correct |
2 |
Correct |
1 ms |
564 KB |
Output is correct |
3 |
Correct |
1 ms |
468 KB |
Output is correct |
4 |
Correct |
1 ms |
568 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
1 ms |
468 KB |
Output is correct |
7 |
Correct |
1 ms |
568 KB |
Output is correct |
8 |
Correct |
1 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
544 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
1 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
1 ms |
596 KB |
Output is correct |
14 |
Correct |
1 ms |
468 KB |
Output is correct |
15 |
Correct |
1 ms |
596 KB |
Output is correct |
16 |
Correct |
1 ms |
2132 KB |
Output is correct |
17 |
Correct |
1 ms |
2132 KB |
Output is correct |
18 |
Correct |
1 ms |
2132 KB |
Output is correct |
19 |
Correct |
2 ms |
2132 KB |
Output is correct |
20 |
Correct |
2 ms |
2132 KB |
Output is correct |
21 |
Correct |
1 ms |
2108 KB |
Output is correct |
22 |
Correct |
2 ms |
2132 KB |
Output is correct |
23 |
Correct |
2 ms |
2132 KB |
Output is correct |
24 |
Correct |
2 ms |
2132 KB |
Output is correct |
25 |
Correct |
2 ms |
2132 KB |
Output is correct |
26 |
Correct |
2 ms |
2132 KB |
Output is correct |
27 |
Correct |
2 ms |
2132 KB |
Output is correct |
28 |
Correct |
1 ms |
2132 KB |
Output is correct |
29 |
Correct |
2 ms |
2132 KB |
Output is correct |
30 |
Correct |
2 ms |
2132 KB |
Output is correct |
31 |
Correct |
2 ms |
2132 KB |
Output is correct |
32 |
Correct |
2 ms |
2132 KB |
Output is correct |
33 |
Correct |
2 ms |
2132 KB |
Output is correct |
34 |
Correct |
2 ms |
2132 KB |
Output is correct |
35 |
Correct |
2 ms |
2132 KB |
Output is correct |
36 |
Correct |
1 ms |
2132 KB |
Output is correct |
37 |
Correct |
2 ms |
2132 KB |
Output is correct |
38 |
Correct |
2 ms |
2104 KB |
Output is correct |
39 |
Correct |
2 ms |
2132 KB |
Output is correct |
40 |
Correct |
2 ms |
2132 KB |
Output is correct |
41 |
Correct |
53 ms |
41380 KB |
Output is correct |
42 |
Correct |
48 ms |
41428 KB |
Output is correct |
43 |
Correct |
100 ms |
41440 KB |
Output is correct |
44 |
Correct |
97 ms |
41400 KB |
Output is correct |
45 |
Correct |
206 ms |
41428 KB |
Output is correct |
46 |
Correct |
204 ms |
41372 KB |
Output is correct |
47 |
Correct |
332 ms |
41428 KB |
Output is correct |
48 |
Correct |
345 ms |
41428 KB |
Output is correct |
49 |
Correct |
485 ms |
41428 KB |
Output is correct |
50 |
Correct |
481 ms |
41428 KB |
Output is correct |
51 |
Correct |
670 ms |
41428 KB |
Output is correct |
52 |
Correct |
668 ms |
41428 KB |
Output is correct |
53 |
Correct |
337 ms |
41384 KB |
Output is correct |
54 |
Correct |
333 ms |
41424 KB |
Output is correct |
55 |
Correct |
345 ms |
41428 KB |
Output is correct |
56 |
Correct |
334 ms |
41424 KB |
Output is correct |
57 |
Correct |
336 ms |
41428 KB |
Output is correct |
58 |
Correct |
329 ms |
41428 KB |
Output is correct |
59 |
Correct |
347 ms |
41548 KB |
Output is correct |
60 |
Correct |
329 ms |
41428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2656 ms |
1004328 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
276 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Execution timed out |
2625 ms |
1004316 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |