#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<pair<ll, ll>>
#define pp pair<ll, ll>
#define qi queue<ll>
#define qp queue<pp>
#define pqi priority_queue<ll>
#define pqp priority_queue<pp>
#define mi map<ll, ll>
#define mpi map<pp, ll>
#define mip map<ll, pp>
#define mpp map<pp, pp>
#define mb map<ll, bool>
#define si set<ll>
#define sp set<pp>
#define mod 1000000007
#define rep(a, b) for(int a = 0; a < (b); a++)
#define rep2(a, b) for(int a = 1; a < (b); a++)
#define inf 1000000000000000000
vi A, B;
vp C;
ll n, k;
double solve(ll m) {
vector<vector<vector<double>>> dp(n);
rep(i, n) {
dp[i].resize(k + 1);
rep(j, dp[i].size()) {
dp[i][j].resize(m + 1);
rep(l, dp[i][j].size()) {
dp[i][j][l] = inf;
}
}
}
dp[0][0][0] = 0;
dp[0][1][0] = C[0].second;
dp[0][1][1] = C[0].first;
for (int i = 1; i < dp.size(); i++) {
rep(j, dp[i].size()) {
rep(l, dp[i][j].size()) {
dp[i][j][l] = dp[i - 1][j][l];
if (j > 0) {
dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j - 1][l] + 1.0 * C[i].second / (m + 1));
if (l > 0) {
dp[i][j][l] = min(dp[i][j][l], dp[i - 1][j - 1][l - 1] + 1.0 * C[i].first / (l));
}
}
}
}
}
return dp[n - 1][k][m];
}
int main()
{
cin >> n >> k;
A.resize(n);
B.resize(n);
C.resize(n);
rep(i, n) {
cin >> A[i] >> B[i];
if (B[i] == -1) {
B[i] = inf;
}
C[i] = { B[i], A[i] };
}
sort(C.begin(), C.end());
double MIN = 19811595300000.95;
rep(i, k) {
MIN = min(MIN, solve(i + 1));
}
sort(A.begin(), A.end());
double ans1 = 0;
rep(i, k) {
ans1 += A[i];
}
MIN = min(MIN, ans1);
cout << fixed << MIN << endl;
}
Compilation message
Main.cpp: In function 'double solve(long long int)':
Main.cpp:24:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define rep(a, b) for(int a = 0; a < (b); a++)
| ^
Main.cpp:37:9: note: in expansion of macro 'rep'
37 | rep(j, dp[i].size()) {
| ^~~
Main.cpp:24:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define rep(a, b) for(int a = 0; a < (b); a++)
| ^
Main.cpp:39:13: note: in expansion of macro 'rep'
39 | rep(l, dp[i][j].size()) {
| ^~~
Main.cpp:47:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<std::vector<double> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
47 | for (int i = 1; i < dp.size(); i++) {
| ~~^~~~~~~~~~~
Main.cpp:24:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<double> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define rep(a, b) for(int a = 0; a < (b); a++)
| ^
Main.cpp:48:9: note: in expansion of macro 'rep'
48 | rep(j, dp[i].size()) {
| ^~~
Main.cpp:24:36: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<double>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
24 | #define rep(a, b) for(int a = 0; a < (b); a++)
| ^
Main.cpp:49:13: note: in expansion of macro 'rep'
49 | rep(l, dp[i][j].size()) {
| ^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
274 ms |
11568 KB |
Output is correct |
6 |
Execution timed out |
2527 ms |
54612 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
274 ms |
11568 KB |
Output is correct |
6 |
Execution timed out |
2527 ms |
54612 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
424 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
424 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
424 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
432 KB |
Output is correct |
6 |
Correct |
1 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2604 ms |
108352 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
274 ms |
11568 KB |
Output is correct |
6 |
Execution timed out |
2527 ms |
54612 KB |
Time limit exceeded |
7 |
Halted |
0 ms |
0 KB |
- |