This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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));
}
}
swap(dp1, dp2);
}
ans = min(ans, dp1[x][s]);
}
cout << fixed << setprecision(15) << ans;
}
return 0;
}
# | 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... |