#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
const int N = 550;
int n, x;
pair<int, int> a[N];
double dp1[N][N], dp2[N][N];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int tt = 1;
//cin >> tt;
while (tt--) {
cin >> n >> x;
for (int i = 1;i <= n;i++) {
cin >> a[i].f >> a[i].s;
if (a[i].s == -1)
a[i].s = 1e9;
}
sort(a + 1, a + n + 1, [&](pair<int, int> x, pair<int, int> y) {
return x.s < y.s;
});
//prvih i, dobio sam j glasova, k ljudi ucestvuje
double ans = 1e9;
for (int s = 1;s <= n;s++) {
for (int j = 0;j <= n;j++) {
for (int k = 0;k <= n;k++)
dp1[j][k] = 1e9;
}
dp1[0][1] = 0;
for (int i = 1;i <= n;i++) {
for (int j = 1;j <= n;j++) {
for (int k = 1;k <= n;k++) {
dp2[j][k] = dp1[j][k];
dp2[j][k] = min(dp2[j][k], dp1[j - 1][k] + (double)a[i].f / s);
if (k > 1)
dp2[j][k] = min(dp2[j][k], dp1[j - 1][k - 1] + (double)a[i].s / (k - 1));
}
}
for (int j = 0;j <= n;j++) {
for (int k = 0;k <= n;k++) {
dp1[j][k] = dp2[j][k];
dp2[j][k] = 1e9;
}
}
}
ans = min(ans, dp1[x][s]);
}
cout << fixed << setprecision(15) << ans;
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Execution timed out |
2585 ms |
4956 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Execution timed out |
2585 ms |
4956 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
2392 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
2599 ms |
4956 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
2 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2392 KB |
Output is correct |
5 |
Execution timed out |
2585 ms |
4956 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |