#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];
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;
}
sort(c + 1, c + n + 1, [](pair<ld, ld> x, pair<ld, ld> y) {return x.second < y.second;});
// for(int i = 1; i <= n; i++)
// cout << c[i].first << ' ' << c[i].second << '\n';
// cout << '\n';
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;
// for(int k = 1; k <= n; k++) {
// for(int v = 1; v <= n; v++) {
// cout <<setprecision(1) << fixed << dp[k][v] << ' ';
// }
// cout << '\n';
// }
// cout << '\n';
}
ld res = INF;
for(int v = 1; v <= n; v++) {
res = min(res, dp[k][v]);
}
cout << setprecision(9) << fixed << res ;
}
# |
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 |
968 ms |
8452 KB |
Output is correct |
6 |
Correct |
958 ms |
8552 KB |
Output is correct |
7 |
Correct |
1117 ms |
8344 KB |
Output is correct |
8 |
Correct |
1088 ms |
8412 KB |
Output is correct |
9 |
Correct |
1130 ms |
8412 KB |
Output is correct |
10 |
Correct |
1024 ms |
8440 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 |
968 ms |
8452 KB |
Output is correct |
6 |
Correct |
958 ms |
8552 KB |
Output is correct |
7 |
Correct |
1117 ms |
8344 KB |
Output is correct |
8 |
Correct |
1088 ms |
8412 KB |
Output is correct |
9 |
Correct |
1130 ms |
8412 KB |
Output is correct |
10 |
Correct |
1024 ms |
8440 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1168 ms |
8440 KB |
Output is correct |
13 |
Correct |
997 ms |
8540 KB |
Output is correct |
14 |
Correct |
995 ms |
8508 KB |
Output is correct |
15 |
Correct |
1135 ms |
8576 KB |
Output is correct |
16 |
Correct |
984 ms |
8448 KB |
Output is correct |
17 |
Correct |
951 ms |
8404 KB |
Output is correct |
18 |
Correct |
1101 ms |
8484 KB |
Output is correct |
19 |
Correct |
926 ms |
8468 KB |
Output is correct |
20 |
Correct |
923 ms |
8496 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 |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1093 ms |
8396 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
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 |
968 ms |
8452 KB |
Output is correct |
6 |
Correct |
958 ms |
8552 KB |
Output is correct |
7 |
Correct |
1117 ms |
8344 KB |
Output is correct |
8 |
Correct |
1088 ms |
8412 KB |
Output is correct |
9 |
Correct |
1130 ms |
8412 KB |
Output is correct |
10 |
Correct |
1024 ms |
8440 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1168 ms |
8440 KB |
Output is correct |
13 |
Correct |
997 ms |
8540 KB |
Output is correct |
14 |
Correct |
995 ms |
8508 KB |
Output is correct |
15 |
Correct |
1135 ms |
8576 KB |
Output is correct |
16 |
Correct |
984 ms |
8448 KB |
Output is correct |
17 |
Correct |
951 ms |
8404 KB |
Output is correct |
18 |
Correct |
1101 ms |
8484 KB |
Output is correct |
19 |
Correct |
926 ms |
8468 KB |
Output is correct |
20 |
Correct |
923 ms |
8496 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 |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Incorrect |
0 ms |
212 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |