#include <bits/stdc++.h>
#define ll long long
#define ar array
#define db double
#define all(x) x.begin(), x.end()
#define sz(x) (int)x.size()
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define rint(l, r) uniform_int_distribution<int>(l, r)(rng)
template<typename T> bool ckmin(T &a, const T &b) { return a > b ? a = b, 1 : 0; }
template<typename T> bool ckmax(T &a, const T &b) { return a < b ? a = b, 1 : 0; }
void test_case() {
int n, k;
cin >> n >> k;
vector<ar<int, 2>> a(n);
for (auto &x : a) cin >> x[0] >> x[1];
// let us use z people in the end
// then, we must first take z-1 Bs, and those Bs will be taken in increasing order
// As must be taken afterwards and can be taken in arbitrary order
db ans = 1e18;
int cnt = 0;
for (int i = 0; i < n; i++) cnt += bool(~a[i][1]);
sort(all(a), [&](const auto &A, const auto &B) { return A[1] < B[1]; });
for (int i = 1; i <= min(cnt, k) + 1; i++) {
// use i people in the end
vector<db> dp(i+1, 1e18);
dp[1] = 0;
for (int j = 0; j < n; j++) {
vector<db> dp2(i+1, 1e18);
for (int l = 1; l <= i; l++) {
if (~a[j][1] && l + 1 <= i) {
ckmin(dp2[l+1], dp[l] + (db)a[j][1] / l);
}
ckmin(dp2[l], dp[l] + (db)a[j][0] / i);
}
swap(dp, dp2);
}
ckmin(ans, dp[i]);
}
cout << fixed << setprecision(10) << ans << '\n';
}
int main() {
cin.tie(0)->sync_with_stdio(0);
int t = 1;
// cin >> t;
while (t--) test_case();
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
162 ms |
516 KB |
Output is correct |
2 |
Correct |
153 ms |
536 KB |
Output is correct |
3 |
Correct |
155 ms |
348 KB |
Output is correct |
4 |
Correct |
154 ms |
512 KB |
Output is correct |
5 |
Correct |
160 ms |
520 KB |
Output is correct |
6 |
Correct |
154 ms |
516 KB |
Output is correct |
7 |
Correct |
157 ms |
516 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
600 KB |
Output is correct |
3 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |