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;
const int inf = 1e18;
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 = inf;
}
sort(a + 1, a + n + 1, [&](pair<int, int> x, pair<int, int> y) {
if (x.s == y.s)
return x.f > y.f;
return x.s < y.s;
});
for (int i = 0;i <= n;i++) {
for (int j = 0;j <= n;j++) {
dp1[i][j] = inf;
}
}
dp1[0][1] = 0;
//prvih i, dobio sam j glasova, k ljudi je samnom
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 / k);
dp2[j][k] = min(dp2[j][k], dp1[j - 1][k - 1] + (double)a[i].s / (k - 1));
}
}
for (int j = 1;j <= n;j++) {
for (int k = 1;k <= n;k++)
dp1[j][k] = dp2[j][k];
}
}
double ans = inf;
for (int i = 1;i <= n;i++)
ans = min(ans, dp1[x][i]);
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... |