#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct Election {
int a, b;
};
bool operator<(const Election &a1, const Election &a2) {
if (a1.b < a2.b) return true;
if (a1.b > a2.b) return false;
if (a1.a < a2.a) return true;
return false;
}
int N, K;
Election X[509];
ll dp[509][509][509];
ll CONST = 1000000000;
ll solve(int Goal) {
// Initialize [1]
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= min(i, K); j++) {
if (i == j) {
for (int k = 0; k <= min(j, Goal); k++) dp[i][j][k] = (1LL << 60);
}
else {
dp[i][j][Goal] = (1LL << 60);
}
}
}
dp[0][0][0] = 0;
for (int i = 0; i < N; i++) {
for (int j = max(0, K - N + i); j <= min(i, K); j++) {
if (i == j) {
for (int k = max(0, Goal - N + i); k <= min(j, Goal); k++) {
dp[i + 1][j + 0][k + 0] = min(dp[i + 1][j + 0][k + 0], dp[i][j][k]);
dp[i + 1][j + 1][k + 0] = min(dp[i + 1][j + 1][k + 0], dp[i][j][k] + CONST * X[i + 1].a / (Goal + 1));
dp[i + 1][j + 1][k + 1] = min(dp[i + 1][j + 1][k + 1], dp[i][j][k] + CONST * X[i + 1].b / (k + 1));
}
}
else {
dp[i + 1][j + 0][Goal] = min(dp[i + 1][j + 0][Goal], dp[i][j][Goal]);
dp[i + 1][j + 1][Goal] = min(dp[i + 1][j + 1][Goal], dp[i][j][Goal] + CONST * X[i + 1].a / (Goal + 1));
}
}
}
return dp[N][K][Goal];
}
int main() {
cin >> N >> K;
for (int i = 1; i <= N; i++) {
cin >> X[i].a >> X[i].b;
if (X[i].b == -1) X[i].b = 1000000;
}
// solve
sort(X + 1, X + N + 1);
ll ans = 1LL << 60;
for (int i = 0; i <= K; i++) {
ll ret = solve(i);
ans = min(ans, solve(i));
}
// ans
printf("%lld.%09lld\n", ans / CONST, ans % CONST);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |