This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#ifdef LOCAL
//#define _GLIBCXX_DEBUG
#endif
#include <bits/stdc++.h>
#include <random>
#ifndef LOCAL
//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,bmi,bmi2,popcnt,lzcnt")
#endif
using namespace std;
using ll = long long;
using ld = long double;
#define x first
#define y second
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
mt19937_64 mt(418);
void solve();
void init();
int32_t main() {
#ifndef LOCAL
cin.tie(nullptr)->sync_with_stdio(false);
#endif
// srand(time(0));
init();
cout << fixed << setprecision(20);
int t = 1;
// cin >> t;
while (t--) {
solve();
}
}
void init() {}
bool cmp(const pair<int, int>& a, const pair<int, int>& b) {
if (a.y < b.y) {
return true;
}
if (a.y > b.y) {
return false;
}
return a.x < b.x;
}
double dp[510][510][510]{};
void solve() {
int n, k;
cin >> n >> k;
vector<pair<int, int>> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i].x >> a[i].y;
if (a[i].y == -1) {
a[i].y = INT32_MAX / 2;
}
}
double ans = 2e18;
double dell[510];
for (int i = 1; i < 510; i++) {
dell[i] = 1.0 / i;
}
// vector<vector<vector<double>>> dp(n + 1, vector<vector<double>>(k + 1, vector<double>(n + 1, 2e18)));
for (int i = 0; i < 510; i++) {
for (int j = 0; j < 510; j++) {
for (int l = 0; l < 510; l++) {
dp[i][j][l] = 2e18;
}
}
}
for (int ll = 0; ll <= n; ll++) {
sort(all(a), cmp);
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
if (i == j - 1) {
for (int l = 0; l <= n; l++) {
dp[i + 1][j][l] = 3e18;
}
} else {
dp[i + 1][j][ll] = 3e18;
}
}
}
dp[0][0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k; j++) {
if (i == j - 1) {
for (int l = 0; l <= n; l++) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j][l]);
if (j > 0) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j - 1][l] + a[i].x * dell[ll + 1]);
if (l > 0) {
dp[i + 1][j][l] = min(dp[i + 1][j][l], dp[i][j - 1][l - 1] + a[i].y * dell[l]);
}
}
}
} else {
dp[i + 1][j][ll] = min(dp[i + 1][j][ll], dp[i][j][ll]);
if (j > 0) {
dp[i + 1][j][ll] = min(dp[i + 1][j][ll], dp[i][j - 1][ll] + a[i].x * dell[ll + 1]);
}
}
}
}
for (int i = ll; i <= n; i++) {
ans = min(ans, dp[n][k][i]);
}
}
cout << ans << '\n';
}
# | 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... |