#include <bits/stdc++.h>
using namespace std;
const int N = 505;
double dp[N][N];
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n, k; cin >> n >> k;
vector<array<int, 2>> a(n);
for(auto &[i, l]: a) cin >> i >> l;
sort(a.begin(), a.end(), [&](auto x, auto y){
if(x[1]==y[1]) return x[0] < y[0];
else if(y[1]==-1) return true;
else if(x[1]==-1) return false;
return x[1]<y[1];
});
auto calc=[&](int e){
for(int i=0; i<=n+1; i++){
for(int l=0; l<=n+1; l++){
dp[i][l]=1e9;
}
}
dp[0][0]=0;
for(int i=0; i<n; i++){
for(int l=e; l>=0; l--){
for(int x=n; x>=0; x--){
// cout<<(double)a[i][1]/(double)(l+1)<<"\n";
if(a[i][1]!=-1)
dp[l+1][x] =min<double>(dp[l+1][x], dp[l][x]+(double)a[i][1]/(double)(l+1));
dp[l][x+1]=min<double>(dp[l][x+1], dp[l][x]+((double)a[i][0]/(double)(e+1)));
}
}
}
return dp[e][k-e];
};
double ans=1e9;
int s=0;
for(int i=9; i>=0; i--){
int tmp = s+(1<<i);
if(tmp<=k && calc(tmp)<calc(tmp-1)){
s=tmp;
ans=min(ans, calc(tmp));
}
}
for(int i=max(0,s-5); i<=min(k, s+5); i++){
ans=min(ans, calc(i));
}
cout<<setprecision(9)<<ans<<"\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2448 KB |
Output is correct |
6 |
Correct |
56 ms |
2392 KB |
Output is correct |
7 |
Correct |
111 ms |
2424 KB |
Output is correct |
8 |
Correct |
219 ms |
2424 KB |
Output is correct |
9 |
Correct |
209 ms |
2420 KB |
Output is correct |
10 |
Correct |
211 ms |
2392 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2448 KB |
Output is correct |
6 |
Correct |
56 ms |
2392 KB |
Output is correct |
7 |
Correct |
111 ms |
2424 KB |
Output is correct |
8 |
Correct |
219 ms |
2424 KB |
Output is correct |
9 |
Correct |
209 ms |
2420 KB |
Output is correct |
10 |
Correct |
211 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1197 ms |
2428 KB |
Output is correct |
13 |
Correct |
947 ms |
2424 KB |
Output is correct |
14 |
Correct |
378 ms |
2396 KB |
Output is correct |
15 |
Execution timed out |
2565 ms |
2396 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
0 ms |
600 KB |
Output is correct |
17 |
Correct |
1 ms |
344 KB |
Output is correct |
18 |
Correct |
1 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
344 KB |
Output is correct |
24 |
Correct |
1 ms |
344 KB |
Output is correct |
25 |
Correct |
1 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
0 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
600 KB |
Output is correct |
34 |
Correct |
1 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
344 KB |
Output is correct |
41 |
Correct |
2 ms |
860 KB |
Output is correct |
42 |
Correct |
4 ms |
860 KB |
Output is correct |
43 |
Correct |
4 ms |
604 KB |
Output is correct |
44 |
Correct |
8 ms |
856 KB |
Output is correct |
45 |
Correct |
16 ms |
860 KB |
Output is correct |
46 |
Correct |
8 ms |
856 KB |
Output is correct |
47 |
Correct |
12 ms |
860 KB |
Output is correct |
48 |
Correct |
19 ms |
860 KB |
Output is correct |
49 |
Correct |
26 ms |
860 KB |
Output is correct |
50 |
Correct |
17 ms |
864 KB |
Output is correct |
51 |
Correct |
23 ms |
604 KB |
Output is correct |
52 |
Correct |
30 ms |
860 KB |
Output is correct |
53 |
Correct |
8 ms |
604 KB |
Output is correct |
54 |
Correct |
14 ms |
860 KB |
Output is correct |
55 |
Correct |
22 ms |
860 KB |
Output is correct |
56 |
Correct |
10 ms |
604 KB |
Output is correct |
57 |
Correct |
22 ms |
604 KB |
Output is correct |
58 |
Correct |
23 ms |
860 KB |
Output is correct |
59 |
Correct |
26 ms |
600 KB |
Output is correct |
60 |
Correct |
19 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2528 ms |
2392 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
32 ms |
2448 KB |
Output is correct |
6 |
Correct |
56 ms |
2392 KB |
Output is correct |
7 |
Correct |
111 ms |
2424 KB |
Output is correct |
8 |
Correct |
219 ms |
2424 KB |
Output is correct |
9 |
Correct |
209 ms |
2420 KB |
Output is correct |
10 |
Correct |
211 ms |
2392 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
1197 ms |
2428 KB |
Output is correct |
13 |
Correct |
947 ms |
2424 KB |
Output is correct |
14 |
Correct |
378 ms |
2396 KB |
Output is correct |
15 |
Execution timed out |
2565 ms |
2396 KB |
Time limit exceeded |
16 |
Halted |
0 ms |
0 KB |
- |