#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)
#define all(a) a.begin() , a.end()
#define F first
#define S second
using namespace std;
using ll = long long;
const int N = 500+5 , inf = 2e9 + 7;
const ll INF = 1e18 , mod = 1e9+7 , P = 6547;
int a[N], b[N];
double dp[N][N][N];
void mini(double &a, double b) {
a = min(a, b);
}
void solve(int tc) {
int n , k;
cin >> n >> k;
vector<pair<int,int>> vec;
for(int i = 1; i <= n; i ++) {
cin >> a[i] >> b[i];
if(b[i] == -1) b[i] = inf;
vec.push_back({b[i] , a[i]});
}
sort(all(vec));
for(int i = 1; i <= n; i ++) {
a[i] = vec[i-1].S;
b[i] = vec[i-1].F;
}
for(int i = 0; i <= n; i ++) {
for(int j = 0; j <= n; j ++) {
for(int k = 0; k <= n; k ++) {
dp[i][j][k] = INF;
}
}
}
for(int i = 0; i <= n; i ++) dp[i][0][0] = 0;
double ans = INF;
for(int l = 0; l <= n; l ++) { // в конце сторонников
for(int i = 0; i < n; i ++) {
for(int j = 0; j <= i; j ++) {
mini(dp[i+1][j][l], dp[i][j][l]);
mini(dp[i+1][j+1][l], dp[i][j][l] + a[i+1]/double(l+1));
if(i == j)
for(int x = 0; x <= min(j, l); x ++) {
mini(dp[i+1][j][x], dp[i][j][x]);
mini(dp[i+1][j+1][x], dp[i][j][x] + a[i+1]/double(l+1));
if(b[i+1] != inf)
mini(dp[i+1][j+1][x+1], dp[i][j][x] + b[i+1]/double(x+1));
}
}
}
ans = min(ans, dp[n][k][l]);
}
cout << fixed << setprecision(6) << ans;
}
/*
*/
main() {
ios;
int tt = 1 , tc = 0;
// cin >> tt;
while(tt --) {
solve(++tc);
}
return 0;
}
Compilation message
Main.cpp:66:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
66 | main() {
| ^~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1306 ms |
994532 KB |
Output is correct |
6 |
Correct |
1379 ms |
994576 KB |
Output is correct |
7 |
Correct |
1336 ms |
994572 KB |
Output is correct |
8 |
Correct |
1316 ms |
994588 KB |
Output is correct |
9 |
Correct |
1452 ms |
994556 KB |
Output is correct |
10 |
Correct |
1331 ms |
994544 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1306 ms |
994532 KB |
Output is correct |
6 |
Correct |
1379 ms |
994576 KB |
Output is correct |
7 |
Correct |
1336 ms |
994572 KB |
Output is correct |
8 |
Correct |
1316 ms |
994588 KB |
Output is correct |
9 |
Correct |
1452 ms |
994556 KB |
Output is correct |
10 |
Correct |
1331 ms |
994544 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1378 ms |
994532 KB |
Output is correct |
13 |
Correct |
1308 ms |
994596 KB |
Output is correct |
14 |
Correct |
1379 ms |
994632 KB |
Output is correct |
15 |
Correct |
1340 ms |
994532 KB |
Output is correct |
16 |
Correct |
1409 ms |
994536 KB |
Output is correct |
17 |
Correct |
1360 ms |
994656 KB |
Output is correct |
18 |
Correct |
1364 ms |
994536 KB |
Output is correct |
19 |
Correct |
1309 ms |
994540 KB |
Output is correct |
20 |
Correct |
1340 ms |
994540 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 ms |
596 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 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 |
2152 KB |
Output is correct |
20 |
Correct |
1 ms |
2132 KB |
Output is correct |
21 |
Correct |
1 ms |
2132 KB |
Output is correct |
22 |
Correct |
1 ms |
2132 KB |
Output is correct |
23 |
Correct |
1 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
2132 KB |
Output is correct |
25 |
Correct |
1 ms |
2132 KB |
Output is correct |
26 |
Correct |
1 ms |
2132 KB |
Output is correct |
27 |
Correct |
1 ms |
2132 KB |
Output is correct |
28 |
Correct |
1 ms |
2132 KB |
Output is correct |
29 |
Correct |
1 ms |
2132 KB |
Output is correct |
30 |
Correct |
1 ms |
2132 KB |
Output is correct |
31 |
Correct |
1 ms |
2132 KB |
Output is correct |
32 |
Correct |
1 ms |
2132 KB |
Output is correct |
33 |
Correct |
1 ms |
2132 KB |
Output is correct |
34 |
Correct |
1 ms |
2132 KB |
Output is correct |
35 |
Correct |
1 ms |
2132 KB |
Output is correct |
36 |
Correct |
2 ms |
2132 KB |
Output is correct |
37 |
Correct |
1 ms |
2132 KB |
Output is correct |
38 |
Correct |
1 ms |
2132 KB |
Output is correct |
39 |
Correct |
1 ms |
2132 KB |
Output is correct |
40 |
Correct |
1 ms |
2132 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
596 KB |
Output is correct |
2 |
Correct |
1 ms |
596 KB |
Output is correct |
3 |
Correct |
1 ms |
596 KB |
Output is correct |
4 |
Correct |
1 ms |
596 KB |
Output is correct |
5 |
Correct |
1 ms |
596 KB |
Output is correct |
6 |
Correct |
1 ms |
596 KB |
Output is correct |
7 |
Correct |
1 ms |
552 KB |
Output is correct |
8 |
Correct |
0 ms |
596 KB |
Output is correct |
9 |
Correct |
1 ms |
596 KB |
Output is correct |
10 |
Correct |
1 ms |
596 KB |
Output is correct |
11 |
Correct |
0 ms |
596 KB |
Output is correct |
12 |
Correct |
1 ms |
596 KB |
Output is correct |
13 |
Correct |
0 ms |
596 KB |
Output is correct |
14 |
Correct |
0 ms |
468 KB |
Output is correct |
15 |
Correct |
0 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 |
2152 KB |
Output is correct |
20 |
Correct |
1 ms |
2132 KB |
Output is correct |
21 |
Correct |
1 ms |
2132 KB |
Output is correct |
22 |
Correct |
1 ms |
2132 KB |
Output is correct |
23 |
Correct |
1 ms |
2132 KB |
Output is correct |
24 |
Correct |
1 ms |
2132 KB |
Output is correct |
25 |
Correct |
1 ms |
2132 KB |
Output is correct |
26 |
Correct |
1 ms |
2132 KB |
Output is correct |
27 |
Correct |
1 ms |
2132 KB |
Output is correct |
28 |
Correct |
1 ms |
2132 KB |
Output is correct |
29 |
Correct |
1 ms |
2132 KB |
Output is correct |
30 |
Correct |
1 ms |
2132 KB |
Output is correct |
31 |
Correct |
1 ms |
2132 KB |
Output is correct |
32 |
Correct |
1 ms |
2132 KB |
Output is correct |
33 |
Correct |
1 ms |
2132 KB |
Output is correct |
34 |
Correct |
1 ms |
2132 KB |
Output is correct |
35 |
Correct |
1 ms |
2132 KB |
Output is correct |
36 |
Correct |
2 ms |
2132 KB |
Output is correct |
37 |
Correct |
1 ms |
2132 KB |
Output is correct |
38 |
Correct |
1 ms |
2132 KB |
Output is correct |
39 |
Correct |
1 ms |
2132 KB |
Output is correct |
40 |
Correct |
1 ms |
2132 KB |
Output is correct |
41 |
Correct |
25 ms |
41064 KB |
Output is correct |
42 |
Correct |
22 ms |
41044 KB |
Output is correct |
43 |
Correct |
24 ms |
41020 KB |
Output is correct |
44 |
Correct |
24 ms |
41036 KB |
Output is correct |
45 |
Correct |
26 ms |
41044 KB |
Output is correct |
46 |
Correct |
21 ms |
41044 KB |
Output is correct |
47 |
Correct |
22 ms |
41060 KB |
Output is correct |
48 |
Correct |
23 ms |
41044 KB |
Output is correct |
49 |
Correct |
22 ms |
41044 KB |
Output is correct |
50 |
Correct |
23 ms |
41036 KB |
Output is correct |
51 |
Correct |
23 ms |
41044 KB |
Output is correct |
52 |
Correct |
23 ms |
41044 KB |
Output is correct |
53 |
Correct |
24 ms |
41044 KB |
Output is correct |
54 |
Correct |
23 ms |
41008 KB |
Output is correct |
55 |
Correct |
22 ms |
41020 KB |
Output is correct |
56 |
Correct |
23 ms |
41044 KB |
Output is correct |
57 |
Correct |
25 ms |
41136 KB |
Output is correct |
58 |
Correct |
23 ms |
41044 KB |
Output is correct |
59 |
Correct |
24 ms |
41040 KB |
Output is correct |
60 |
Correct |
25 ms |
41084 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1333 ms |
994584 KB |
Output is correct |
2 |
Correct |
1436 ms |
994708 KB |
Output is correct |
3 |
Correct |
1383 ms |
994668 KB |
Output is correct |
4 |
Correct |
1371 ms |
994568 KB |
Output is correct |
5 |
Correct |
1398 ms |
994496 KB |
Output is correct |
6 |
Correct |
1312 ms |
994540 KB |
Output is correct |
7 |
Correct |
1385 ms |
994572 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1306 ms |
994532 KB |
Output is correct |
6 |
Correct |
1379 ms |
994576 KB |
Output is correct |
7 |
Correct |
1336 ms |
994572 KB |
Output is correct |
8 |
Correct |
1316 ms |
994588 KB |
Output is correct |
9 |
Correct |
1452 ms |
994556 KB |
Output is correct |
10 |
Correct |
1331 ms |
994544 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1378 ms |
994532 KB |
Output is correct |
13 |
Correct |
1308 ms |
994596 KB |
Output is correct |
14 |
Correct |
1379 ms |
994632 KB |
Output is correct |
15 |
Correct |
1340 ms |
994532 KB |
Output is correct |
16 |
Correct |
1409 ms |
994536 KB |
Output is correct |
17 |
Correct |
1360 ms |
994656 KB |
Output is correct |
18 |
Correct |
1364 ms |
994536 KB |
Output is correct |
19 |
Correct |
1309 ms |
994540 KB |
Output is correct |
20 |
Correct |
1340 ms |
994540 KB |
Output is correct |
21 |
Correct |
1 ms |
596 KB |
Output is correct |
22 |
Correct |
1 ms |
596 KB |
Output is correct |
23 |
Correct |
1 ms |
596 KB |
Output is correct |
24 |
Correct |
1 ms |
596 KB |
Output is correct |
25 |
Correct |
1 ms |
596 KB |
Output is correct |
26 |
Correct |
1 ms |
596 KB |
Output is correct |
27 |
Correct |
1 ms |
552 KB |
Output is correct |
28 |
Correct |
0 ms |
596 KB |
Output is correct |
29 |
Correct |
1 ms |
596 KB |
Output is correct |
30 |
Correct |
1 ms |
596 KB |
Output is correct |
31 |
Correct |
0 ms |
596 KB |
Output is correct |
32 |
Correct |
1 ms |
596 KB |
Output is correct |
33 |
Correct |
0 ms |
596 KB |
Output is correct |
34 |
Correct |
0 ms |
468 KB |
Output is correct |
35 |
Correct |
0 ms |
596 KB |
Output is correct |
36 |
Correct |
1 ms |
2132 KB |
Output is correct |
37 |
Correct |
1 ms |
2132 KB |
Output is correct |
38 |
Correct |
1 ms |
2132 KB |
Output is correct |
39 |
Correct |
2 ms |
2152 KB |
Output is correct |
40 |
Correct |
1 ms |
2132 KB |
Output is correct |
41 |
Correct |
1 ms |
2132 KB |
Output is correct |
42 |
Correct |
1 ms |
2132 KB |
Output is correct |
43 |
Correct |
1 ms |
2132 KB |
Output is correct |
44 |
Correct |
1 ms |
2132 KB |
Output is correct |
45 |
Correct |
1 ms |
2132 KB |
Output is correct |
46 |
Correct |
1 ms |
2132 KB |
Output is correct |
47 |
Correct |
1 ms |
2132 KB |
Output is correct |
48 |
Correct |
1 ms |
2132 KB |
Output is correct |
49 |
Correct |
1 ms |
2132 KB |
Output is correct |
50 |
Correct |
1 ms |
2132 KB |
Output is correct |
51 |
Correct |
1 ms |
2132 KB |
Output is correct |
52 |
Correct |
1 ms |
2132 KB |
Output is correct |
53 |
Correct |
1 ms |
2132 KB |
Output is correct |
54 |
Correct |
1 ms |
2132 KB |
Output is correct |
55 |
Correct |
1 ms |
2132 KB |
Output is correct |
56 |
Correct |
2 ms |
2132 KB |
Output is correct |
57 |
Correct |
1 ms |
2132 KB |
Output is correct |
58 |
Correct |
1 ms |
2132 KB |
Output is correct |
59 |
Correct |
1 ms |
2132 KB |
Output is correct |
60 |
Correct |
1 ms |
2132 KB |
Output is correct |
61 |
Correct |
25 ms |
41064 KB |
Output is correct |
62 |
Correct |
22 ms |
41044 KB |
Output is correct |
63 |
Correct |
24 ms |
41020 KB |
Output is correct |
64 |
Correct |
24 ms |
41036 KB |
Output is correct |
65 |
Correct |
26 ms |
41044 KB |
Output is correct |
66 |
Correct |
21 ms |
41044 KB |
Output is correct |
67 |
Correct |
22 ms |
41060 KB |
Output is correct |
68 |
Correct |
23 ms |
41044 KB |
Output is correct |
69 |
Correct |
22 ms |
41044 KB |
Output is correct |
70 |
Correct |
23 ms |
41036 KB |
Output is correct |
71 |
Correct |
23 ms |
41044 KB |
Output is correct |
72 |
Correct |
23 ms |
41044 KB |
Output is correct |
73 |
Correct |
24 ms |
41044 KB |
Output is correct |
74 |
Correct |
23 ms |
41008 KB |
Output is correct |
75 |
Correct |
22 ms |
41020 KB |
Output is correct |
76 |
Correct |
23 ms |
41044 KB |
Output is correct |
77 |
Correct |
25 ms |
41136 KB |
Output is correct |
78 |
Correct |
23 ms |
41044 KB |
Output is correct |
79 |
Correct |
24 ms |
41040 KB |
Output is correct |
80 |
Correct |
25 ms |
41084 KB |
Output is correct |
81 |
Correct |
1333 ms |
994584 KB |
Output is correct |
82 |
Correct |
1436 ms |
994708 KB |
Output is correct |
83 |
Correct |
1383 ms |
994668 KB |
Output is correct |
84 |
Correct |
1371 ms |
994568 KB |
Output is correct |
85 |
Correct |
1398 ms |
994496 KB |
Output is correct |
86 |
Correct |
1312 ms |
994540 KB |
Output is correct |
87 |
Correct |
1385 ms |
994572 KB |
Output is correct |
88 |
Correct |
1589 ms |
994532 KB |
Output is correct |
89 |
Correct |
1304 ms |
994608 KB |
Output is correct |
90 |
Correct |
1344 ms |
994568 KB |
Output is correct |
91 |
Correct |
1340 ms |
994592 KB |
Output is correct |
92 |
Correct |
1334 ms |
994536 KB |
Output is correct |
93 |
Correct |
1375 ms |
994536 KB |
Output is correct |
94 |
Correct |
1312 ms |
994540 KB |
Output is correct |
95 |
Correct |
1321 ms |
994564 KB |
Output is correct |
96 |
Correct |
1338 ms |
994540 KB |
Output is correct |
97 |
Correct |
1349 ms |
994656 KB |
Output is correct |
98 |
Correct |
1347 ms |
994532 KB |
Output is correct |
99 |
Correct |
1349 ms |
994424 KB |
Output is correct |
100 |
Correct |
1424 ms |
994536 KB |
Output is correct |
101 |
Correct |
1464 ms |
994628 KB |
Output is correct |
102 |
Correct |
1561 ms |
994540 KB |
Output is correct |
103 |
Correct |
1587 ms |
994536 KB |
Output is correct |
104 |
Correct |
1428 ms |
994540 KB |
Output is correct |
105 |
Correct |
1534 ms |
994536 KB |
Output is correct |