#include <bits/stdc++.h>
using namespace std;
int n, k;
bool vis[505][505][505];
double DP[505][505][505], inf = 1e12, cans = inf;
pair<int, int> dat[505];
int main() {
DP[0][0][0] = 0; vis[0][0][0] = 1;
cin >> n >> k;
int bc = n;
for(int i=0;i<n;i++) {
cin >> dat[i].first >> dat[i].second;
if(dat[i].second == -1) bc--, dat[i].second = INT_MAX;
}
sort(dat, dat+n, [](pair<int, int> a, pair<int, int> b){
if(a.second == INT_MAX) return (bool) 0;
if(b.second == INT_MAX) return (bool) 1;
return a.first < b.first;
});
double frfr = 1e12;
int bcc = bc+1;
while (bcc--) {
for(int i=0;i<=n;i++) {
for(int j=0;j<=k;j++) {
for(int K=0;K<=bc;K++) {
if(i == j && j == K && !i) continue;
if(i == 0 || j<K) {DP[i][j][K] = inf; continue;}
DP[i][j][K] = DP[i-1][j][K];
if(j) DP[i][j][K] = min(DP[i][j][K], DP[i-1][j-1][K] + (1.00*dat[i-1].first/(K+1)));
if(j && K && dat[i-1].second != INT_MAX) DP[i][j][K] = min(DP[i][j][K], DP[i-1][j-1][K-1] + (1.00*dat[i-1].second/K));
}
}
}
for(int i=0;i<=bc;i++) cans = min(cans, DP[n][k][i]);
frfr = min(frfr, cans);
rotate(dat, dat+1, dat+bc);
}
cout << frfr;
}
/*
8 8
10 -1
23 31
12 77
45 56
234 -1
123 1341
567 -1
95 342
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
39 ms |
102984 KB |
Output is correct |
6 |
Correct |
87 ms |
251244 KB |
Output is correct |
7 |
Correct |
159 ms |
498324 KB |
Output is correct |
8 |
Correct |
278 ms |
745400 KB |
Output is correct |
9 |
Correct |
283 ms |
992500 KB |
Output is correct |
10 |
Correct |
250 ms |
695984 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
39 ms |
102984 KB |
Output is correct |
6 |
Correct |
87 ms |
251244 KB |
Output is correct |
7 |
Correct |
159 ms |
498324 KB |
Output is correct |
8 |
Correct |
278 ms |
745400 KB |
Output is correct |
9 |
Correct |
283 ms |
992500 KB |
Output is correct |
10 |
Correct |
250 ms |
695984 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
2574 ms |
302684 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
468 KB |
Output is correct |
4 |
Correct |
0 ms |
468 KB |
Output is correct |
5 |
Correct |
0 ms |
468 KB |
Output is correct |
6 |
Correct |
0 ms |
468 KB |
Output is correct |
7 |
Incorrect |
1 ms |
596 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2578 ms |
994492 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
39 ms |
102984 KB |
Output is correct |
6 |
Correct |
87 ms |
251244 KB |
Output is correct |
7 |
Correct |
159 ms |
498324 KB |
Output is correct |
8 |
Correct |
278 ms |
745400 KB |
Output is correct |
9 |
Correct |
283 ms |
992500 KB |
Output is correct |
10 |
Correct |
250 ms |
695984 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Execution timed out |
2574 ms |
302684 KB |
Time limit exceeded |
13 |
Halted |
0 ms |
0 KB |
- |