#include <iostream>
#include <algorithm>
using namespace std;
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];
double dp[509][509]; // (pos, cooperator)
double solve(int Goal) {
// Initialize [1]
for (int i = 0; i <= N; i++) {
for (int j = 0; j <= N; j++) dp[i][j] = 1e9;
}
// Dynamic Programming
dp[0][0] = 0;
for (int i = 1; i <= N; i++) {
for (int j = 0; j <= N; j++) {
if (dp[i - 1][j] > 1e8) continue;
dp[i][j + 0] = min(dp[i][j + 0], dp[i - 1][j] + 1.0 * X[i].a / (Goal + 1));
if (X[i].b != -1) {
dp[i][j + 1] = min(dp[i][j + 1], dp[i - 1][j] + 1.0 * X[i].b / (j + 1));
}
}
}
// Return Value
return dp[N][Goal];
}
int main() {
// Step #1. Input
cin >> N;
cin >> K;
for (int i = 1; i <= N; i++) {
cin >> X[i].a >> X[i].b;
if (X[i].b == -1) X[i].b = 1000000;
}
// Step #2. Sorting
sort(X + 1, X + N + 1);
// Step #3. Brute Force
double Answer = 1e9;
for (int i = 0; i <= K; i++) {
double ret = solve(i);
Answer = min(Answer, ret);
}
// Step #4. Output
printf("%.15lf\n", Answer);
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
332 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
408 ms |
2272 KB |
Output is correct |
2 |
Correct |
368 ms |
2272 KB |
Output is correct |
3 |
Correct |
396 ms |
2276 KB |
Output is correct |
4 |
Correct |
359 ms |
2268 KB |
Output is correct |
5 |
Correct |
368 ms |
2272 KB |
Output is correct |
6 |
Correct |
339 ms |
2272 KB |
Output is correct |
7 |
Correct |
367 ms |
2252 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |