#include <bits/stdc++.h>
using namespace std;
#define all(v) v.begin(), v.end()
typedef long long ll;
const int NMAX = 1e5 + 5;
const int inf = 1e6;
const double eps = 1e-10;
int n, k, a, b;
double dp[505][505];
vector<pair<int, int>> v;
double solve(int x){
double ret = 0;
for(int i = 0; i <= n; i++)
for(int j = 0; j <= n; j++) dp[i][j] = 1e9;
dp[0][0] = 0;
for(int i = 1; i <= n; i++){
auto&[b, a] = v[i - 1];
for(int j = 0; j <= min(i, x); j++){
dp[i][j] = dp[i - 1][j] + 1.0 * a / (x + 1);
if(j && b != inf) dp[i][j] = min(dp[i][j], dp[i - 1][j - 1] + 1.0 * b / j);
}
}
if(dp[n][x] > 1e9 - eps) return 1e9;
vector<double> t;
int j = x;
for(int i = n; i; i--){
auto&[b, a] = v[i - 1];
if(abs(dp[i][j] - dp[i - 1][j] - 1.0 * a / (x + 1)) < eps) t.emplace_back(1.0 * a / (x + 1));
else ret += dp[i][j] - dp[i - 1][j - 1], j--;
}
sort(all(t));
for(int i = 0; i < k - x; i++) ret += t[i];
return ret;
}
int main(void){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> k;
for(int i = 0; i < n; i++){
cin >> a >> b;
if(b == -1) b = inf;
v.emplace_back(b, a);
}
sort(all(v));
double ans = inf;
for(int i = 0; i <= k; i++) ans = min(ans, solve(i));
cout << fixed << setprecision(10) << ans;
return 0;
}
Compilation message
Main.cpp: In function 'double solve(int)':
Main.cpp:20:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
20 | auto&[b, a] = v[i - 1];
| ^
Main.cpp:30:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
30 | auto&[b, a] = v[i - 1];
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
11 ms |
2320 KB |
Output is correct |
6 |
Correct |
26 ms |
2312 KB |
Output is correct |
7 |
Correct |
60 ms |
2300 KB |
Output is correct |
8 |
Correct |
97 ms |
2296 KB |
Output is correct |
9 |
Correct |
115 ms |
2300 KB |
Output is correct |
10 |
Correct |
87 ms |
2304 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
11 ms |
2320 KB |
Output is correct |
6 |
Correct |
26 ms |
2312 KB |
Output is correct |
7 |
Correct |
60 ms |
2300 KB |
Output is correct |
8 |
Correct |
97 ms |
2296 KB |
Output is correct |
9 |
Correct |
115 ms |
2300 KB |
Output is correct |
10 |
Correct |
87 ms |
2304 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
43 ms |
2260 KB |
Output is correct |
13 |
Correct |
36 ms |
2296 KB |
Output is correct |
14 |
Correct |
34 ms |
2248 KB |
Output is correct |
15 |
Correct |
127 ms |
2260 KB |
Output is correct |
16 |
Correct |
95 ms |
2300 KB |
Output is correct |
17 |
Correct |
79 ms |
2260 KB |
Output is correct |
18 |
Correct |
187 ms |
2296 KB |
Output is correct |
19 |
Correct |
140 ms |
2260 KB |
Output is correct |
20 |
Correct |
117 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
328 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
324 KB |
Output is correct |
12 |
Correct |
0 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
324 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
19 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
182 ms |
2300 KB |
Output is correct |
2 |
Correct |
153 ms |
2260 KB |
Output is correct |
3 |
Correct |
154 ms |
2304 KB |
Output is correct |
4 |
Correct |
165 ms |
2304 KB |
Output is correct |
5 |
Correct |
173 ms |
2308 KB |
Output is correct |
6 |
Correct |
186 ms |
2300 KB |
Output is correct |
7 |
Correct |
151 ms |
2300 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
324 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
11 ms |
2320 KB |
Output is correct |
6 |
Correct |
26 ms |
2312 KB |
Output is correct |
7 |
Correct |
60 ms |
2300 KB |
Output is correct |
8 |
Correct |
97 ms |
2296 KB |
Output is correct |
9 |
Correct |
115 ms |
2300 KB |
Output is correct |
10 |
Correct |
87 ms |
2304 KB |
Output is correct |
11 |
Correct |
1 ms |
324 KB |
Output is correct |
12 |
Correct |
43 ms |
2260 KB |
Output is correct |
13 |
Correct |
36 ms |
2296 KB |
Output is correct |
14 |
Correct |
34 ms |
2248 KB |
Output is correct |
15 |
Correct |
127 ms |
2260 KB |
Output is correct |
16 |
Correct |
95 ms |
2300 KB |
Output is correct |
17 |
Correct |
79 ms |
2260 KB |
Output is correct |
18 |
Correct |
187 ms |
2296 KB |
Output is correct |
19 |
Correct |
140 ms |
2260 KB |
Output is correct |
20 |
Correct |
117 ms |
2300 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
328 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
0 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
324 KB |
Output is correct |
32 |
Correct |
0 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
324 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Incorrect |
1 ms |
328 KB |
Output isn't correct |
39 |
Halted |
0 ms |
0 KB |
- |