#include <bits/stdc++.h>
using namespace std;
#define int int64_t
signed main() {
cin.tie(0);
ios_base::sync_with_stdio(0);
int n, K; cin >> n >> K;
vector<array<int, 3>> inputA(n);
vector<array<int, 3>> inputB(n);
for (int i=0; i<n; i++) {
int a, b; cin >> a >> b;
if (b == -1) b = 1e18;
inputA[i]={a, b, i};
inputB[i]={b, a, i};
}
sort(inputA.begin(), inputA.end());
sort(inputB.begin(), inputB.end());
// vector<bool> topK(n, 0);
// for (int i = 0; i<K; i++) {
// topK[inputA[i][2]] = 1;
// }
double res = 1e10;
array<array<double, 505>, 505> dp;
for (int i=0; i<n; i++) {
for (auto &a: dp) for (auto &b: a) b = 1e10;
dp[0][0] = 0;
for (int j=0; j<n; j++) {
for (int k=0; k<=min(i, j); k++) {
// cerr << dp[j][k] << " ";
if (dp[j][k] == 1e10) continue;
dp[j+1][k] = min(dp[j+1][k], dp[j][k]+(double)inputB[j][1]/(double)(i+1));
dp[j+1][k+1] = min(dp[j+1][k+1], dp[j][k]+(double)inputB[j][0]/(double)(k+1));
}
// cerr << "\n";
}
// cerr << "\n";
res = min(res, dp[n][i]);
}
// for (int colabs = 0; colabs<=K; colabs++) {
// for (int inTopK = 0; inTopK<=K; inTopK++) {
// double tmp = dp[n][inTopK][colabs];
// cerr << tmp << "\n";
// if (tmp == 1e10) continue;
// for (int i = 0; i<K+inTopK; i++) {
// tmp += inputA[i][0];
// }
// res = min(res, tmp);
// cerr << "-" << tmp << "\n";
// }
// }
cout.precision(100);
cout << res << "\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
253 ms |
2320 KB |
Output is correct |
2 |
Correct |
259 ms |
2260 KB |
Output is correct |
3 |
Correct |
240 ms |
2320 KB |
Output is correct |
4 |
Correct |
246 ms |
2320 KB |
Output is correct |
5 |
Correct |
231 ms |
2316 KB |
Output is correct |
6 |
Correct |
244 ms |
2312 KB |
Output is correct |
7 |
Correct |
234 ms |
2316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2260 KB |
Output is correct |
2 |
Correct |
2 ms |
2260 KB |
Output is correct |
3 |
Incorrect |
2 ms |
2260 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |