#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;
constexpr int maxn = 501, inf = 1e9 + 7;
constexpr double eps = 1e-4;
double dp[maxn][maxn][maxn];
double ans_vl[maxn];
double get_ans(int n, int k, vector<double> &a, vector<pair<double, int>> &s_b, int cnt_all) {
if (ans_vl[cnt_all] >= 0.5) {
return ans_vl[cnt_all];
}
for (int i = 0; i <= n; ++i) {
for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) {
for (int cnt_used = 0; cnt_used <= k; ++cnt_used) {
dp[i][cnt_nw][cnt_used] = inf;
}
}
}
dp[0][0][0] = 0;
double ans = inf;
for (int i = 0; i < n; ++i) {
for (int cnt_nw = 0; cnt_nw <= i && cnt_nw <= cnt_all; ++cnt_nw) {
for (int cnt_used = cnt_nw; cnt_used < k; ++cnt_used) {
if (s_b[i].first < 10000 && cnt_nw < cnt_all) {
dp[i + 1][cnt_nw + 1][cnt_used + 1] = min(dp[i + 1][cnt_nw + 1][cnt_used + 1], dp[i][cnt_nw][cnt_used] + s_b[i].first / (cnt_nw + 1));
if (cnt_used + 1 == k && cnt_nw + 1 == cnt_all) {
ans = min(ans, dp[i + 1][cnt_nw + 1][cnt_used + 1]);
}
}
dp[i + 1][cnt_nw][cnt_used + 1] = min(dp[i + 1][cnt_nw][cnt_used + 1], dp[i][cnt_nw][cnt_used] + a[s_b[i].second] / (cnt_all + 1));
if (cnt_used + 1 == k && cnt_nw == cnt_all) {
ans = min(ans, dp[i + 1][cnt_nw][cnt_used + 1]);
}
dp[i + 1][cnt_nw][cnt_used] = min(dp[i + 1][cnt_nw][cnt_used], dp[i][cnt_nw][cnt_used]);
}
}
}
ans_vl[cnt_all] = ans;
return ans;
}
void solve() {
int n, k;
cin >> n >> k;
vector<double> a(n), b(n);
vector<pair<double, int>> s_b;
for (int i = 0; i < n; ++i) {
cin >> a[i] >> b[i];
if (b[i] > 0) {
s_b.emplace_back(b[i], i);
} else {
s_b.emplace_back(inf, i);
}
}
sort(s_b.begin(), s_b.end());
double ans = get_ans(n, k, a, s_b, 0);
int l = 0, r = k;
while (l < r - 3) {
int m1 = l + (r - l) / 3;
int m2 = r - (r - l) / 3;
double ans1 = get_ans(n, k, a, s_b, m1);
double ans2 = get_ans(n, k, a, s_b, m2);
ans = min(ans, min(ans1, ans2));
if (ans1 >= ans2) {
l = m1;
} else {
r = m2;
}
}
for (int i = l + 1; i < r; ++i) {
ans = min(ans, get_ans(n, k, a, s_b, i));
}
cout << ans << '\n';
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.precision(25);
cout << fixed;
int t = 1;
// cin >> t;
while (t--) {
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8536 KB |
Output is correct |
5 |
Correct |
195 ms |
623956 KB |
Output is correct |
6 |
Correct |
412 ms |
685464 KB |
Output is correct |
7 |
Correct |
1373 ms |
786400 KB |
Output is correct |
8 |
Execution timed out |
2501 ms |
874684 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8536 KB |
Output is correct |
5 |
Correct |
195 ms |
623956 KB |
Output is correct |
6 |
Correct |
412 ms |
685464 KB |
Output is correct |
7 |
Correct |
1373 ms |
786400 KB |
Output is correct |
8 |
Execution timed out |
2501 ms |
874684 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14816 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
2 ms |
14684 KB |
Output is correct |
14 |
Correct |
1 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14816 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
2 ms |
14684 KB |
Output is correct |
14 |
Correct |
1 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
41308 KB |
Output is correct |
17 |
Correct |
5 ms |
41308 KB |
Output is correct |
18 |
Correct |
5 ms |
41308 KB |
Output is correct |
19 |
Correct |
4 ms |
41304 KB |
Output is correct |
20 |
Correct |
5 ms |
41308 KB |
Output is correct |
21 |
Correct |
4 ms |
41308 KB |
Output is correct |
22 |
Correct |
5 ms |
41516 KB |
Output is correct |
23 |
Correct |
4 ms |
41308 KB |
Output is correct |
24 |
Correct |
5 ms |
41308 KB |
Output is correct |
25 |
Correct |
4 ms |
41308 KB |
Output is correct |
26 |
Correct |
4 ms |
41304 KB |
Output is correct |
27 |
Correct |
4 ms |
41464 KB |
Output is correct |
28 |
Correct |
5 ms |
41500 KB |
Output is correct |
29 |
Correct |
5 ms |
41308 KB |
Output is correct |
30 |
Correct |
5 ms |
41308 KB |
Output is correct |
31 |
Correct |
5 ms |
41308 KB |
Output is correct |
32 |
Correct |
4 ms |
41480 KB |
Output is correct |
33 |
Correct |
5 ms |
41308 KB |
Output is correct |
34 |
Correct |
5 ms |
41308 KB |
Output is correct |
35 |
Correct |
5 ms |
41308 KB |
Output is correct |
36 |
Correct |
5 ms |
41304 KB |
Output is correct |
37 |
Correct |
4 ms |
41308 KB |
Output is correct |
38 |
Correct |
5 ms |
41308 KB |
Output is correct |
39 |
Correct |
4 ms |
41308 KB |
Output is correct |
40 |
Correct |
5 ms |
41308 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14680 KB |
Output is correct |
2 |
Correct |
2 ms |
14684 KB |
Output is correct |
3 |
Correct |
2 ms |
14804 KB |
Output is correct |
4 |
Correct |
2 ms |
14684 KB |
Output is correct |
5 |
Correct |
2 ms |
14684 KB |
Output is correct |
6 |
Correct |
2 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14684 KB |
Output is correct |
9 |
Correct |
2 ms |
14816 KB |
Output is correct |
10 |
Correct |
2 ms |
14684 KB |
Output is correct |
11 |
Correct |
2 ms |
14684 KB |
Output is correct |
12 |
Correct |
2 ms |
14684 KB |
Output is correct |
13 |
Correct |
2 ms |
14684 KB |
Output is correct |
14 |
Correct |
1 ms |
10588 KB |
Output is correct |
15 |
Correct |
2 ms |
14684 KB |
Output is correct |
16 |
Correct |
4 ms |
41308 KB |
Output is correct |
17 |
Correct |
5 ms |
41308 KB |
Output is correct |
18 |
Correct |
5 ms |
41308 KB |
Output is correct |
19 |
Correct |
4 ms |
41304 KB |
Output is correct |
20 |
Correct |
5 ms |
41308 KB |
Output is correct |
21 |
Correct |
4 ms |
41308 KB |
Output is correct |
22 |
Correct |
5 ms |
41516 KB |
Output is correct |
23 |
Correct |
4 ms |
41308 KB |
Output is correct |
24 |
Correct |
5 ms |
41308 KB |
Output is correct |
25 |
Correct |
4 ms |
41308 KB |
Output is correct |
26 |
Correct |
4 ms |
41304 KB |
Output is correct |
27 |
Correct |
4 ms |
41464 KB |
Output is correct |
28 |
Correct |
5 ms |
41500 KB |
Output is correct |
29 |
Correct |
5 ms |
41308 KB |
Output is correct |
30 |
Correct |
5 ms |
41308 KB |
Output is correct |
31 |
Correct |
5 ms |
41308 KB |
Output is correct |
32 |
Correct |
4 ms |
41480 KB |
Output is correct |
33 |
Correct |
5 ms |
41308 KB |
Output is correct |
34 |
Correct |
5 ms |
41308 KB |
Output is correct |
35 |
Correct |
5 ms |
41308 KB |
Output is correct |
36 |
Correct |
5 ms |
41304 KB |
Output is correct |
37 |
Correct |
4 ms |
41308 KB |
Output is correct |
38 |
Correct |
5 ms |
41308 KB |
Output is correct |
39 |
Correct |
4 ms |
41308 KB |
Output is correct |
40 |
Correct |
5 ms |
41308 KB |
Output is correct |
41 |
Correct |
19 ms |
197200 KB |
Output is correct |
42 |
Correct |
19 ms |
197364 KB |
Output is correct |
43 |
Correct |
20 ms |
197464 KB |
Output is correct |
44 |
Correct |
20 ms |
197212 KB |
Output is correct |
45 |
Correct |
24 ms |
197200 KB |
Output is correct |
46 |
Correct |
25 ms |
197208 KB |
Output is correct |
47 |
Correct |
26 ms |
197232 KB |
Output is correct |
48 |
Correct |
28 ms |
197468 KB |
Output is correct |
49 |
Correct |
33 ms |
197204 KB |
Output is correct |
50 |
Correct |
28 ms |
197468 KB |
Output is correct |
51 |
Correct |
36 ms |
197468 KB |
Output is correct |
52 |
Correct |
40 ms |
197200 KB |
Output is correct |
53 |
Correct |
25 ms |
197412 KB |
Output is correct |
54 |
Correct |
26 ms |
197208 KB |
Output is correct |
55 |
Correct |
27 ms |
197212 KB |
Output is correct |
56 |
Correct |
24 ms |
197212 KB |
Output is correct |
57 |
Correct |
27 ms |
197200 KB |
Output is correct |
58 |
Correct |
30 ms |
197440 KB |
Output is correct |
59 |
Correct |
30 ms |
197204 KB |
Output is correct |
60 |
Correct |
29 ms |
197288 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2534 ms |
894212 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8536 KB |
Output is correct |
5 |
Correct |
195 ms |
623956 KB |
Output is correct |
6 |
Correct |
412 ms |
685464 KB |
Output is correct |
7 |
Correct |
1373 ms |
786400 KB |
Output is correct |
8 |
Execution timed out |
2501 ms |
874684 KB |
Time limit exceeded |
9 |
Halted |
0 ms |
0 KB |
- |