#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
const int N = 500;
const ld INF = 1e16;
int n, k;
pair<ld, ld> c[N + 10];
bool is1Subtask = 1;
ll w[(1 << 20)][20];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n >> k;
for(int i = 1; i <= n; i++) {
cin >> c[i].first >> c[i].second;
if(c[i].second == -1) c[i].second = INF;
is1Subtask &= (c[i].second == c[i].first || c[i].second == INF);
}
sort(c + 1, c + n + 1, [](pair<ld, ld> x, pair<ld, ld> y) {return x.second < y.second;});
if(is1Subtask) {
vector<vector<ld>> dp(n + 1, vector<ld>(n + 1, INF));
dp[0][1] = 0;
for(int i = 1; i <= n; i++) {
vector<vector<ld>> newdp = dp;
for(int k = 1; k <= i; k++) {
for(int v = 1; v <= i + 1; v++) {
newdp[k][v] = min(newdp[k][v], dp[k - 1][v] + c[i].first / v);
if(v > 1 && c[i].second != INF)
newdp[k][v] = min(newdp[k][v], dp[k - 1][v - 1] + c[i].second / (v - 1)) ;
}
}
dp = newdp;
}
ld res = INF;
for(int v = 1; v <= n; v++) {
res = min(res, dp[k][v]);
}
cout << setprecision(9) << fixed << res ;
return 0;
}
if(n <= 20) {
ld res = INF;
for(int msk = 0; msk < (1 << n); msk++) {
vector<ll> v;
vector<ll> w(n + 1, -1);
ld sum = 0, veloc = 1;
for(int i = 0; i < n; i++) {
if(msk >> i & 1) {
sum += c[i + 1].second / veloc;
veloc++;
} else {
v.push_back(c[i + 1].first);
}
}
sort(v.begin(), v.end());
for(int i = 0; i <= k - veloc; i++)
sum += v[i] / veloc;
res = min(res, sum);
}
cout << setprecision(9) << fixed << res ;
return 0;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
922 ms |
8352 KB |
Output is correct |
6 |
Correct |
912 ms |
8512 KB |
Output is correct |
7 |
Correct |
919 ms |
8496 KB |
Output is correct |
8 |
Correct |
980 ms |
8508 KB |
Output is correct |
9 |
Correct |
998 ms |
8476 KB |
Output is correct |
10 |
Correct |
974 ms |
8480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
922 ms |
8352 KB |
Output is correct |
6 |
Correct |
912 ms |
8512 KB |
Output is correct |
7 |
Correct |
919 ms |
8496 KB |
Output is correct |
8 |
Correct |
980 ms |
8508 KB |
Output is correct |
9 |
Correct |
998 ms |
8476 KB |
Output is correct |
10 |
Correct |
974 ms |
8480 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1166 ms |
8428 KB |
Output is correct |
13 |
Correct |
992 ms |
8532 KB |
Output is correct |
14 |
Correct |
947 ms |
8504 KB |
Output is correct |
15 |
Correct |
1108 ms |
8472 KB |
Output is correct |
16 |
Correct |
951 ms |
8420 KB |
Output is correct |
17 |
Correct |
923 ms |
8452 KB |
Output is correct |
18 |
Correct |
1116 ms |
8536 KB |
Output is correct |
19 |
Correct |
1041 ms |
8468 KB |
Output is correct |
20 |
Correct |
932 ms |
8528 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
372 ms |
324 KB |
Output is correct |
17 |
Correct |
330 ms |
340 KB |
Output is correct |
18 |
Correct |
326 ms |
320 KB |
Output is correct |
19 |
Correct |
364 ms |
324 KB |
Output is correct |
20 |
Correct |
353 ms |
340 KB |
Output is correct |
21 |
Correct |
363 ms |
212 KB |
Output is correct |
22 |
Correct |
392 ms |
340 KB |
Output is correct |
23 |
Correct |
366 ms |
340 KB |
Output is correct |
24 |
Correct |
367 ms |
340 KB |
Output is correct |
25 |
Correct |
416 ms |
316 KB |
Output is correct |
26 |
Correct |
419 ms |
324 KB |
Output is correct |
27 |
Correct |
378 ms |
340 KB |
Output is correct |
28 |
Correct |
374 ms |
320 KB |
Output is correct |
29 |
Correct |
387 ms |
340 KB |
Output is correct |
30 |
Correct |
401 ms |
324 KB |
Output is correct |
31 |
Correct |
425 ms |
340 KB |
Output is correct |
32 |
Correct |
390 ms |
340 KB |
Output is correct |
33 |
Correct |
406 ms |
212 KB |
Output is correct |
34 |
Correct |
376 ms |
328 KB |
Output is correct |
35 |
Correct |
366 ms |
340 KB |
Output is correct |
36 |
Correct |
367 ms |
340 KB |
Output is correct |
37 |
Correct |
355 ms |
340 KB |
Output is correct |
38 |
Correct |
349 ms |
340 KB |
Output is correct |
39 |
Correct |
337 ms |
320 KB |
Output is correct |
40 |
Correct |
316 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
384 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
372 ms |
324 KB |
Output is correct |
17 |
Correct |
330 ms |
340 KB |
Output is correct |
18 |
Correct |
326 ms |
320 KB |
Output is correct |
19 |
Correct |
364 ms |
324 KB |
Output is correct |
20 |
Correct |
353 ms |
340 KB |
Output is correct |
21 |
Correct |
363 ms |
212 KB |
Output is correct |
22 |
Correct |
392 ms |
340 KB |
Output is correct |
23 |
Correct |
366 ms |
340 KB |
Output is correct |
24 |
Correct |
367 ms |
340 KB |
Output is correct |
25 |
Correct |
416 ms |
316 KB |
Output is correct |
26 |
Correct |
419 ms |
324 KB |
Output is correct |
27 |
Correct |
378 ms |
340 KB |
Output is correct |
28 |
Correct |
374 ms |
320 KB |
Output is correct |
29 |
Correct |
387 ms |
340 KB |
Output is correct |
30 |
Correct |
401 ms |
324 KB |
Output is correct |
31 |
Correct |
425 ms |
340 KB |
Output is correct |
32 |
Correct |
390 ms |
340 KB |
Output is correct |
33 |
Correct |
406 ms |
212 KB |
Output is correct |
34 |
Correct |
376 ms |
328 KB |
Output is correct |
35 |
Correct |
366 ms |
340 KB |
Output is correct |
36 |
Correct |
367 ms |
340 KB |
Output is correct |
37 |
Correct |
355 ms |
340 KB |
Output is correct |
38 |
Correct |
349 ms |
340 KB |
Output is correct |
39 |
Correct |
337 ms |
320 KB |
Output is correct |
40 |
Correct |
316 ms |
212 KB |
Output is correct |
41 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
42 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
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 |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
922 ms |
8352 KB |
Output is correct |
6 |
Correct |
912 ms |
8512 KB |
Output is correct |
7 |
Correct |
919 ms |
8496 KB |
Output is correct |
8 |
Correct |
980 ms |
8508 KB |
Output is correct |
9 |
Correct |
998 ms |
8476 KB |
Output is correct |
10 |
Correct |
974 ms |
8480 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1166 ms |
8428 KB |
Output is correct |
13 |
Correct |
992 ms |
8532 KB |
Output is correct |
14 |
Correct |
947 ms |
8504 KB |
Output is correct |
15 |
Correct |
1108 ms |
8472 KB |
Output is correct |
16 |
Correct |
951 ms |
8420 KB |
Output is correct |
17 |
Correct |
923 ms |
8452 KB |
Output is correct |
18 |
Correct |
1116 ms |
8536 KB |
Output is correct |
19 |
Correct |
1041 ms |
8468 KB |
Output is correct |
20 |
Correct |
932 ms |
8528 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 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 |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 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 |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
384 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
372 ms |
324 KB |
Output is correct |
37 |
Correct |
330 ms |
340 KB |
Output is correct |
38 |
Correct |
326 ms |
320 KB |
Output is correct |
39 |
Correct |
364 ms |
324 KB |
Output is correct |
40 |
Correct |
353 ms |
340 KB |
Output is correct |
41 |
Correct |
363 ms |
212 KB |
Output is correct |
42 |
Correct |
392 ms |
340 KB |
Output is correct |
43 |
Correct |
366 ms |
340 KB |
Output is correct |
44 |
Correct |
367 ms |
340 KB |
Output is correct |
45 |
Correct |
416 ms |
316 KB |
Output is correct |
46 |
Correct |
419 ms |
324 KB |
Output is correct |
47 |
Correct |
378 ms |
340 KB |
Output is correct |
48 |
Correct |
374 ms |
320 KB |
Output is correct |
49 |
Correct |
387 ms |
340 KB |
Output is correct |
50 |
Correct |
401 ms |
324 KB |
Output is correct |
51 |
Correct |
425 ms |
340 KB |
Output is correct |
52 |
Correct |
390 ms |
340 KB |
Output is correct |
53 |
Correct |
406 ms |
212 KB |
Output is correct |
54 |
Correct |
376 ms |
328 KB |
Output is correct |
55 |
Correct |
366 ms |
340 KB |
Output is correct |
56 |
Correct |
367 ms |
340 KB |
Output is correct |
57 |
Correct |
355 ms |
340 KB |
Output is correct |
58 |
Correct |
349 ms |
340 KB |
Output is correct |
59 |
Correct |
337 ms |
320 KB |
Output is correct |
60 |
Correct |
316 ms |
212 KB |
Output is correct |
61 |
Incorrect |
1 ms |
340 KB |
Output isn't correct |
62 |
Halted |
0 ms |
0 KB |
- |