#include <bits/stdc++.h>
#include <ios>
#include <iostream>
#include <set>
#include <random>
using namespace std;
using ll = double;
using P = pair<double, double>;
#define f first
#define s second
const ll MOD = 1e9+7;
const ll inf = 4*1e18;
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};
long long md(long long a, long long m) {
return (a % m + m) % m;
}
int main() {
// freopen("input.in", "r", stdin);
ios::sync_with_stdio(false); cin.tie(nullptr);
ll n, k; cin >> n >> k;
vector<P> v;
for (int i = 0; i < n; i++) {
ll x, y; cin >> x >> y;
v.push_back({y, x});
}
sort(v.begin(), v.end());
for (int i = 0; i < n; i++) {
ll tmp = v[i].f;
v[i].f = v[i].s;
v[i].s = tmp;
}
ll M = 1e9;
vector<vector<vector<ll>>> save(n+1, vector<vector<ll>>(n, vector<ll>(n, 1e9)));
for (int j = 0; j <= n; j++) {
save[j][0][0] = 0;
}
ll id = 0;
for (int i = 0; i <= k; i++) {
ll vote = k-i;
ll coll = i;
vector<vector<ll>> dp(2, vector<ll>(vote+1, 1e9));
if (coll == 0) {
dp[1][0] = 0;
} else if (coll == 1) {
dp[0][0] = 0;
}
for (int j = 0; j < n; j++) {
vector<vector<ll>> ndp(2, vector<ll>(vote+1, 1e9));
for (int r = 0; r <= 1; r++) {
for (int w = 0; w <= vote; w++) {
ll rnew = r+(coll-1);
if (rnew == coll-1) {
if (w > 0) ndp[r][w] = dp[r][w-1] + v[j].f/(coll+1);
if (rnew > 0 && v[j].s != -1) ndp[r][w] = min(ndp[r][w], save[j][rnew-1][w] + v[j].s/rnew);
if (rnew >= 0) save[j+1][rnew][w] = ndp[r][w];
} else {
ndp[r][w] = dp[r][w];
if (rnew > 0 && v[j].s != -1) ndp[r][w] = min(ndp[r][w], dp[r-1][w] + v[j].s/rnew);
if (w > 0) ndp[r][w] = min(ndp[r][w], dp[r][w-1] + (v[j].f)/(coll+1));
}
ndp[r][w] = min(ndp[r][w], dp[r][w]);
}
}
swap(dp, ndp);
}
M = min(M, dp[1][vote]);
}
cout << M;
}
| # | 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... |