//JOI 2022 Final round
#include<bits/stdc++.h>
using namespace std;
const double INF=1e9+7;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.precision(100);
int n, k;
cin >> n >> k;
vector<int> a(n);
vector<int> b(n);
for(int i=0; i<n; i++){
cin >> a[i] >> b[i];
if(b[i]==-1) b[i]=INF;
}
vector<int> sorted(n);
iota(sorted.begin(), sorted.end(), 0);
sort(sorted.begin(), sorted.end(), [&](int i, int j){
return b[i]<b[j];
});
double ans=INF;
for(int c=0; c<=k; c++){
vector<vector<double> > dp(n+1, vector<double> (k+1, INF));
dp[0][0]=0;
for(int i=0; i<n; i++){
for(int j=0; j<= min(i+1, k); j++){
int x=i+1-j;
int ind=sorted[i];
if(0<x && x<=c){
dp[i+1][j] = dp[i][j] + (double)b[ind]/(double)x;
}
else if(c<x){
dp[i+1][j] = dp[i][j];
}
if(0<j){
dp[i+1][j] = min(dp[i+1][j], dp[i][j-1] + (double)a[ind]/(double)(c+1));
}
}
}
ans = min(ans, dp[n][k-c]);
}
cout << ans << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
536 KB |
Output is correct |
6 |
Correct |
26 ms |
836 KB |
Output is correct |
7 |
Correct |
106 ms |
1332 KB |
Output is correct |
8 |
Correct |
235 ms |
2064 KB |
Output is correct |
9 |
Correct |
382 ms |
2492 KB |
Output is correct |
10 |
Correct |
209 ms |
1864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
536 KB |
Output is correct |
6 |
Correct |
26 ms |
836 KB |
Output is correct |
7 |
Correct |
106 ms |
1332 KB |
Output is correct |
8 |
Correct |
235 ms |
2064 KB |
Output is correct |
9 |
Correct |
382 ms |
2492 KB |
Output is correct |
10 |
Correct |
209 ms |
1864 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
50 ms |
916 KB |
Output is correct |
13 |
Correct |
40 ms |
924 KB |
Output is correct |
14 |
Correct |
40 ms |
1396 KB |
Output is correct |
15 |
Correct |
209 ms |
1964 KB |
Output is correct |
16 |
Correct |
206 ms |
1724 KB |
Output is correct |
17 |
Correct |
218 ms |
1956 KB |
Output is correct |
18 |
Correct |
410 ms |
2484 KB |
Output is correct |
19 |
Correct |
401 ms |
2604 KB |
Output is correct |
20 |
Correct |
385 ms |
2472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
320 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
320 KB |
Output is correct |
38 |
Correct |
1 ms |
324 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
0 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
0 ms |
324 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
0 ms |
320 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
320 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
320 KB |
Output is correct |
38 |
Correct |
1 ms |
324 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
2 ms |
388 KB |
Output is correct |
50 |
Correct |
2 ms |
340 KB |
Output is correct |
51 |
Correct |
2 ms |
340 KB |
Output is correct |
52 |
Correct |
2 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
54 |
Correct |
2 ms |
340 KB |
Output is correct |
55 |
Correct |
2 ms |
324 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
389 ms |
2492 KB |
Output is correct |
2 |
Correct |
389 ms |
2512 KB |
Output is correct |
3 |
Correct |
382 ms |
2592 KB |
Output is correct |
4 |
Correct |
383 ms |
2500 KB |
Output is correct |
5 |
Correct |
391 ms |
2516 KB |
Output is correct |
6 |
Correct |
385 ms |
2472 KB |
Output is correct |
7 |
Correct |
400 ms |
2472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
536 KB |
Output is correct |
6 |
Correct |
26 ms |
836 KB |
Output is correct |
7 |
Correct |
106 ms |
1332 KB |
Output is correct |
8 |
Correct |
235 ms |
2064 KB |
Output is correct |
9 |
Correct |
382 ms |
2492 KB |
Output is correct |
10 |
Correct |
209 ms |
1864 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
50 ms |
916 KB |
Output is correct |
13 |
Correct |
40 ms |
924 KB |
Output is correct |
14 |
Correct |
40 ms |
1396 KB |
Output is correct |
15 |
Correct |
209 ms |
1964 KB |
Output is correct |
16 |
Correct |
206 ms |
1724 KB |
Output is correct |
17 |
Correct |
218 ms |
1956 KB |
Output is correct |
18 |
Correct |
410 ms |
2484 KB |
Output is correct |
19 |
Correct |
401 ms |
2604 KB |
Output is correct |
20 |
Correct |
385 ms |
2472 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
0 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
0 ms |
212 KB |
Output is correct |
36 |
Correct |
0 ms |
324 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
0 ms |
320 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
0 ms |
212 KB |
Output is correct |
42 |
Correct |
0 ms |
320 KB |
Output is correct |
43 |
Correct |
0 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
0 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
0 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
324 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
212 KB |
Output is correct |
53 |
Correct |
1 ms |
212 KB |
Output is correct |
54 |
Correct |
0 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
0 ms |
324 KB |
Output is correct |
57 |
Correct |
0 ms |
320 KB |
Output is correct |
58 |
Correct |
1 ms |
324 KB |
Output is correct |
59 |
Correct |
0 ms |
212 KB |
Output is correct |
60 |
Correct |
0 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
212 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
340 KB |
Output is correct |
67 |
Correct |
1 ms |
340 KB |
Output is correct |
68 |
Correct |
1 ms |
340 KB |
Output is correct |
69 |
Correct |
2 ms |
388 KB |
Output is correct |
70 |
Correct |
2 ms |
340 KB |
Output is correct |
71 |
Correct |
2 ms |
340 KB |
Output is correct |
72 |
Correct |
2 ms |
340 KB |
Output is correct |
73 |
Correct |
1 ms |
324 KB |
Output is correct |
74 |
Correct |
2 ms |
340 KB |
Output is correct |
75 |
Correct |
2 ms |
324 KB |
Output is correct |
76 |
Correct |
2 ms |
340 KB |
Output is correct |
77 |
Correct |
1 ms |
340 KB |
Output is correct |
78 |
Correct |
1 ms |
340 KB |
Output is correct |
79 |
Correct |
1 ms |
340 KB |
Output is correct |
80 |
Correct |
1 ms |
320 KB |
Output is correct |
81 |
Correct |
389 ms |
2492 KB |
Output is correct |
82 |
Correct |
389 ms |
2512 KB |
Output is correct |
83 |
Correct |
382 ms |
2592 KB |
Output is correct |
84 |
Correct |
383 ms |
2500 KB |
Output is correct |
85 |
Correct |
391 ms |
2516 KB |
Output is correct |
86 |
Correct |
385 ms |
2472 KB |
Output is correct |
87 |
Correct |
400 ms |
2472 KB |
Output is correct |
88 |
Correct |
5 ms |
540 KB |
Output is correct |
89 |
Correct |
5 ms |
540 KB |
Output is correct |
90 |
Correct |
26 ms |
836 KB |
Output is correct |
91 |
Correct |
27 ms |
840 KB |
Output is correct |
92 |
Correct |
106 ms |
1324 KB |
Output is correct |
93 |
Correct |
106 ms |
1316 KB |
Output is correct |
94 |
Correct |
255 ms |
1924 KB |
Output is correct |
95 |
Correct |
228 ms |
1816 KB |
Output is correct |
96 |
Correct |
321 ms |
2112 KB |
Output is correct |
97 |
Correct |
319 ms |
2224 KB |
Output is correct |
98 |
Correct |
212 ms |
1804 KB |
Output is correct |
99 |
Correct |
208 ms |
1788 KB |
Output is correct |
100 |
Correct |
202 ms |
2004 KB |
Output is correct |
101 |
Correct |
206 ms |
2064 KB |
Output is correct |
102 |
Correct |
202 ms |
2000 KB |
Output is correct |
103 |
Correct |
213 ms |
1996 KB |
Output is correct |
104 |
Correct |
206 ms |
1936 KB |
Output is correct |
105 |
Correct |
234 ms |
1716 KB |
Output is correct |