#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MX = 505;
int N, K;
int a[MX], b[MX];
double dp[MX][MX][MX];
vector<pair<int, int>> v;
int main() {
cin.tie(0); ios_base::sync_with_stdio(0);
for(int i = 0; i < MX; i++)
for(int j = 0; j < MX; j++)
for(int k = 0; k < MX; k++)
dp[i][j][k] = 1e9;
cin >> N >> K;
int tot = 0;
for(int i = 1; i <= N; i++) {
cin >> a[i] >> b[i];
if(b[i] != -1) tot++;
else b[i] = 1e9;
v.push_back({b[i], a[i]});
}
sort(v.begin(), v.end(), [&](auto x, auto y) {
return x.first - x.second < y.first - y.second;
});
dp[0][0][0] = 0;
for(int i = 0; i <= N; i++) {
for(int j = 0; j <= N; j++) { // votes
for(int k = 0; k <= N; k++) { // num of collaborator
if(dp[i][j][k] == 1e9) continue;
// skip
dp[i + 1][j][k] = min(dp[i + 1][j][k], dp[i][j][k]);
// ambil vote
dp[i + 1][j + 1][k] = min(dp[i + 1][j + 1][k], dp[i][j][k] + (double) v[i].second / (k + 1));
// ambil collaborator
if(v[i].first != 1e9)
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + (double) v[i].first / (k + 1));
}
}
}
double ans = 1e9;
for(int k = 0; k <= N; k++) {
ans = min(ans, dp[N][K][k]);
}
cout << fixed << setprecision(15) << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
1008400 KB |
Output is correct |
2 |
Correct |
358 ms |
1008352 KB |
Output is correct |
3 |
Correct |
365 ms |
1008352 KB |
Output is correct |
4 |
Correct |
355 ms |
1008400 KB |
Output is correct |
5 |
Correct |
507 ms |
1008416 KB |
Output is correct |
6 |
Correct |
455 ms |
1008620 KB |
Output is correct |
7 |
Correct |
447 ms |
1008324 KB |
Output is correct |
8 |
Correct |
455 ms |
1008348 KB |
Output is correct |
9 |
Correct |
476 ms |
1008332 KB |
Output is correct |
10 |
Correct |
452 ms |
1008332 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
1008400 KB |
Output is correct |
2 |
Correct |
358 ms |
1008352 KB |
Output is correct |
3 |
Correct |
365 ms |
1008352 KB |
Output is correct |
4 |
Correct |
355 ms |
1008400 KB |
Output is correct |
5 |
Correct |
507 ms |
1008416 KB |
Output is correct |
6 |
Correct |
455 ms |
1008620 KB |
Output is correct |
7 |
Correct |
447 ms |
1008324 KB |
Output is correct |
8 |
Correct |
455 ms |
1008348 KB |
Output is correct |
9 |
Correct |
476 ms |
1008332 KB |
Output is correct |
10 |
Correct |
452 ms |
1008332 KB |
Output is correct |
11 |
Correct |
358 ms |
1008472 KB |
Output is correct |
12 |
Incorrect |
520 ms |
1008432 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
1008316 KB |
Output is correct |
2 |
Correct |
350 ms |
1008344 KB |
Output is correct |
3 |
Correct |
355 ms |
1008428 KB |
Output is correct |
4 |
Correct |
364 ms |
1008316 KB |
Output is correct |
5 |
Correct |
359 ms |
1008300 KB |
Output is correct |
6 |
Correct |
350 ms |
1008392 KB |
Output is correct |
7 |
Incorrect |
352 ms |
1008336 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
1008316 KB |
Output is correct |
2 |
Correct |
350 ms |
1008344 KB |
Output is correct |
3 |
Correct |
355 ms |
1008428 KB |
Output is correct |
4 |
Correct |
364 ms |
1008316 KB |
Output is correct |
5 |
Correct |
359 ms |
1008300 KB |
Output is correct |
6 |
Correct |
350 ms |
1008392 KB |
Output is correct |
7 |
Incorrect |
352 ms |
1008336 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
356 ms |
1008316 KB |
Output is correct |
2 |
Correct |
350 ms |
1008344 KB |
Output is correct |
3 |
Correct |
355 ms |
1008428 KB |
Output is correct |
4 |
Correct |
364 ms |
1008316 KB |
Output is correct |
5 |
Correct |
359 ms |
1008300 KB |
Output is correct |
6 |
Correct |
350 ms |
1008392 KB |
Output is correct |
7 |
Incorrect |
352 ms |
1008336 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
523 ms |
1008436 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
417 ms |
1008400 KB |
Output is correct |
2 |
Correct |
358 ms |
1008352 KB |
Output is correct |
3 |
Correct |
365 ms |
1008352 KB |
Output is correct |
4 |
Correct |
355 ms |
1008400 KB |
Output is correct |
5 |
Correct |
507 ms |
1008416 KB |
Output is correct |
6 |
Correct |
455 ms |
1008620 KB |
Output is correct |
7 |
Correct |
447 ms |
1008324 KB |
Output is correct |
8 |
Correct |
455 ms |
1008348 KB |
Output is correct |
9 |
Correct |
476 ms |
1008332 KB |
Output is correct |
10 |
Correct |
452 ms |
1008332 KB |
Output is correct |
11 |
Correct |
358 ms |
1008472 KB |
Output is correct |
12 |
Incorrect |
520 ms |
1008432 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |