#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f first
#define s second
#define pb push_back
#define ep emplace
#define eb emplace_back
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define uniquev(v) sort(all(v)), (v).resize(unique(all(v)) - (v).begin())
#define mem(f,x) memset(f , x , sizeof(f))
#define sz(x) (ll)(x).size()
#define __lcm(a, b) (1ll * ((a) / __gcd((a), (b))) * (b))
#define mxx *max_element
#define mnn *min_element
#define cntbit(x) __builtin_popcountll(x)
#define len(x) (int)(x.length())
const int N = 500 + 10;
double a[N], b[N];
double f[N][N], cost[N][N];
int order[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n, k;
cin >> n >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i] >> b[i];
if (b[i] < 0)
b[i] = 1e9;
order[i] = i;
}
sort(order + 1, order + 1 + n, [&] (int x, int y) {return b[x] < b[y];});
vector <double> lst;
for (int i = n; i >= 1; i--) {
lst.pb(a[order[i]]);
sort(all(lst));
double sum = 0;
cost[i][0] = 0;
for (int j = 0; j < sz(lst); j++) {
sum += lst[j];
cost[i][j + 1] = sum;
}
}
double ans = 1e18;
for (int num = 0; num <= k; num++) {
for (int i = 0; i <= k; i++) {
for (int j = 0; j <= k; j++)
f[i][j] = 1e9;
}
f[0][0] = 0;
for (int i = 1; i <= k; i++) {
for (int j = 0; j <= i; j++) {
f[i][j] = f[i - 1][j] + a[order[i]] / double(num + 1);
if (j > 0) {
f[i][j] = min(f[i][j], f[i - 1][j - 1] + b[order[i]] / double(j));
}
if (j == num) {
int r = k - i;
ans = min(ans, f[i][j] + cost[i + 1][r] / double(num + 1));
}
}
}
}
cout << fixed << setprecision(10) << ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
122 ms |
4444 KB |
Output is correct |
2 |
Correct |
126 ms |
4440 KB |
Output is correct |
3 |
Correct |
125 ms |
4456 KB |
Output is correct |
4 |
Correct |
120 ms |
4444 KB |
Output is correct |
5 |
Correct |
119 ms |
4444 KB |
Output is correct |
6 |
Correct |
122 ms |
4444 KB |
Output is correct |
7 |
Correct |
127 ms |
4440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |