#include <bits/stdc++.h>
using namespace std;
typedef long double ld;
#define fi first
#define se second
#define mp make_pair
#define fastIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 505;
const ld inf = 1e12;
vector<ld> suff[N];
ld A[N];
ld B[N];
ld dp[N][N];
void mini(ld &a, ld b){
a = min(a, b);
}
int main(){
fastIO;
//freopen("in.txt","r",stdin);
int n, k;
cin >> n >> k;
vector<pair<ld,ld>> C(n);
for(int i = 0 ; i < n; i ++ ){
cin >> C[i].se >> C[i].fi;
if(C[i].fi == -1) C[i].fi = inf;
}
sort(C.begin(), C.end());
for(int i = 0 ; i < n; i ++ ){
A[i + 1] = C[i].se;
B[i + 1] = C[i].fi;
}
for(int i = n; i >= 1; i -- ){
for(int j = i ; j <= n; j ++ ){
suff[i].push_back(A[j]);
}
sort(suff[i].begin(), suff[i].end());
}
ld res = inf;
ld current;
for(int take = 0; take <= k ; take ++ ){
for(int i = 0 ; i <= n; i ++ ){
for(int j = 0 ; j <= n; j ++ ){
dp[i][j] = inf;
}
}
dp[0][0] = 0;
for(int i = 1; i <= n; i ++ ){
for(int j = 0 ; j <= i ; j ++ ){
if(dp[i - 1][j] == inf) continue;
mini(dp[i][j], dp[i-1][j] + A[i] / ld(take + 1));
mini(dp[i][j+1], dp[i-1][j] + B[i] / ld(j + 1));
}
}
for(int id = take; id <= k; id ++ ){
current = dp[id][take];
for(int j = 0 ; j < k - id; j ++ ){
current += suff[id + 1][j] / ld(take + 1);
}
res = min(res, current);
}
}
cout << fixed << setprecision(9) << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
101 ms |
6860 KB |
Output is correct |
6 |
Correct |
238 ms |
6972 KB |
Output is correct |
7 |
Correct |
496 ms |
6972 KB |
Output is correct |
8 |
Correct |
725 ms |
6968 KB |
Output is correct |
9 |
Correct |
929 ms |
6964 KB |
Output is correct |
10 |
Correct |
704 ms |
6960 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
101 ms |
6860 KB |
Output is correct |
6 |
Correct |
238 ms |
6972 KB |
Output is correct |
7 |
Correct |
496 ms |
6972 KB |
Output is correct |
8 |
Correct |
725 ms |
6968 KB |
Output is correct |
9 |
Correct |
929 ms |
6964 KB |
Output is correct |
10 |
Correct |
704 ms |
6960 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
554 ms |
6976 KB |
Output is correct |
13 |
Correct |
528 ms |
6964 KB |
Output is correct |
14 |
Correct |
476 ms |
6964 KB |
Output is correct |
15 |
Correct |
1163 ms |
6964 KB |
Output is correct |
16 |
Correct |
1131 ms |
6968 KB |
Output is correct |
17 |
Correct |
1037 ms |
6964 KB |
Output is correct |
18 |
Correct |
1627 ms |
6968 KB |
Output is correct |
19 |
Correct |
1654 ms |
6968 KB |
Output is correct |
20 |
Correct |
1461 ms |
6988 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
0 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
332 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
0 ms |
332 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
0 ms |
352 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
332 KB |
Output is correct |
20 |
Correct |
0 ms |
332 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
1 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
1 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
3 ms |
1040 KB |
Output is correct |
42 |
Correct |
3 ms |
972 KB |
Output is correct |
43 |
Correct |
5 ms |
972 KB |
Output is correct |
44 |
Correct |
5 ms |
972 KB |
Output is correct |
45 |
Correct |
8 ms |
1044 KB |
Output is correct |
46 |
Correct |
8 ms |
972 KB |
Output is correct |
47 |
Correct |
10 ms |
1040 KB |
Output is correct |
48 |
Correct |
12 ms |
972 KB |
Output is correct |
49 |
Correct |
16 ms |
972 KB |
Output is correct |
50 |
Correct |
11 ms |
972 KB |
Output is correct |
51 |
Correct |
15 ms |
1036 KB |
Output is correct |
52 |
Correct |
14 ms |
972 KB |
Output is correct |
53 |
Correct |
10 ms |
1048 KB |
Output is correct |
54 |
Correct |
9 ms |
1036 KB |
Output is correct |
55 |
Correct |
10 ms |
1048 KB |
Output is correct |
56 |
Correct |
12 ms |
1040 KB |
Output is correct |
57 |
Correct |
11 ms |
1040 KB |
Output is correct |
58 |
Correct |
11 ms |
1040 KB |
Output is correct |
59 |
Correct |
9 ms |
972 KB |
Output is correct |
60 |
Correct |
13 ms |
1040 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1677 ms |
6980 KB |
Output is correct |
2 |
Correct |
1631 ms |
6972 KB |
Output is correct |
3 |
Correct |
1644 ms |
6968 KB |
Output is correct |
4 |
Correct |
1719 ms |
6960 KB |
Output is correct |
5 |
Correct |
1713 ms |
6968 KB |
Output is correct |
6 |
Correct |
1623 ms |
6968 KB |
Output is correct |
7 |
Correct |
1646 ms |
6968 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
101 ms |
6860 KB |
Output is correct |
6 |
Correct |
238 ms |
6972 KB |
Output is correct |
7 |
Correct |
496 ms |
6972 KB |
Output is correct |
8 |
Correct |
725 ms |
6968 KB |
Output is correct |
9 |
Correct |
929 ms |
6964 KB |
Output is correct |
10 |
Correct |
704 ms |
6960 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
554 ms |
6976 KB |
Output is correct |
13 |
Correct |
528 ms |
6964 KB |
Output is correct |
14 |
Correct |
476 ms |
6964 KB |
Output is correct |
15 |
Correct |
1163 ms |
6964 KB |
Output is correct |
16 |
Correct |
1131 ms |
6968 KB |
Output is correct |
17 |
Correct |
1037 ms |
6964 KB |
Output is correct |
18 |
Correct |
1627 ms |
6968 KB |
Output is correct |
19 |
Correct |
1654 ms |
6968 KB |
Output is correct |
20 |
Correct |
1461 ms |
6988 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
0 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
0 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
0 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
0 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
0 ms |
352 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
0 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
332 KB |
Output is correct |
42 |
Correct |
0 ms |
332 KB |
Output is correct |
43 |
Correct |
1 ms |
332 KB |
Output is correct |
44 |
Correct |
0 ms |
332 KB |
Output is correct |
45 |
Correct |
1 ms |
332 KB |
Output is correct |
46 |
Correct |
1 ms |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
1 ms |
332 KB |
Output is correct |
50 |
Correct |
1 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
332 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
332 KB |
Output is correct |
55 |
Correct |
1 ms |
332 KB |
Output is correct |
56 |
Correct |
1 ms |
332 KB |
Output is correct |
57 |
Correct |
1 ms |
332 KB |
Output is correct |
58 |
Correct |
1 ms |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
3 ms |
1040 KB |
Output is correct |
62 |
Correct |
3 ms |
972 KB |
Output is correct |
63 |
Correct |
5 ms |
972 KB |
Output is correct |
64 |
Correct |
5 ms |
972 KB |
Output is correct |
65 |
Correct |
8 ms |
1044 KB |
Output is correct |
66 |
Correct |
8 ms |
972 KB |
Output is correct |
67 |
Correct |
10 ms |
1040 KB |
Output is correct |
68 |
Correct |
12 ms |
972 KB |
Output is correct |
69 |
Correct |
16 ms |
972 KB |
Output is correct |
70 |
Correct |
11 ms |
972 KB |
Output is correct |
71 |
Correct |
15 ms |
1036 KB |
Output is correct |
72 |
Correct |
14 ms |
972 KB |
Output is correct |
73 |
Correct |
10 ms |
1048 KB |
Output is correct |
74 |
Correct |
9 ms |
1036 KB |
Output is correct |
75 |
Correct |
10 ms |
1048 KB |
Output is correct |
76 |
Correct |
12 ms |
1040 KB |
Output is correct |
77 |
Correct |
11 ms |
1040 KB |
Output is correct |
78 |
Correct |
11 ms |
1040 KB |
Output is correct |
79 |
Correct |
9 ms |
972 KB |
Output is correct |
80 |
Correct |
13 ms |
1040 KB |
Output is correct |
81 |
Correct |
1677 ms |
6980 KB |
Output is correct |
82 |
Correct |
1631 ms |
6972 KB |
Output is correct |
83 |
Correct |
1644 ms |
6968 KB |
Output is correct |
84 |
Correct |
1719 ms |
6960 KB |
Output is correct |
85 |
Correct |
1713 ms |
6968 KB |
Output is correct |
86 |
Correct |
1623 ms |
6968 KB |
Output is correct |
87 |
Correct |
1646 ms |
6968 KB |
Output is correct |
88 |
Correct |
172 ms |
6968 KB |
Output is correct |
89 |
Correct |
206 ms |
6968 KB |
Output is correct |
90 |
Correct |
408 ms |
6968 KB |
Output is correct |
91 |
Correct |
425 ms |
6928 KB |
Output is correct |
92 |
Correct |
808 ms |
6988 KB |
Output is correct |
93 |
Correct |
800 ms |
6964 KB |
Output is correct |
94 |
Correct |
1209 ms |
6972 KB |
Output is correct |
95 |
Correct |
1287 ms |
6988 KB |
Output is correct |
96 |
Correct |
1504 ms |
6968 KB |
Output is correct |
97 |
Correct |
1463 ms |
6968 KB |
Output is correct |
98 |
Correct |
1102 ms |
6968 KB |
Output is correct |
99 |
Correct |
1168 ms |
6968 KB |
Output is correct |
100 |
Correct |
1116 ms |
6968 KB |
Output is correct |
101 |
Correct |
1139 ms |
6988 KB |
Output is correct |
102 |
Correct |
1094 ms |
6964 KB |
Output is correct |
103 |
Correct |
1097 ms |
6964 KB |
Output is correct |
104 |
Correct |
1094 ms |
6988 KB |
Output is correct |
105 |
Correct |
1089 ms |
6968 KB |
Output is correct |