//#pragma GCC optimize("Ofast")
//#pragma GCC target("avx,avx2,sse,sse2,sse3,ssse3,sse4,abm,popcnt,mmx")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef complex<double> cd;
constexpr ll INF64 = 9'000'000'000'000'000'000, INF32 = 2'000'000'000, MOD = 1'000'000'007;
constexpr db PI = acos(-1);
constexpr bool IS_FILE = false, IS_TEST_CASES = false;
random_device rd;
mt19937 rnd32(rd());
mt19937_64 rnd64(rd());
template<typename T>
bool assign_max(T& a, T b) {
if (b > a) {
a = b;
return true;
}
return false;
}
template<typename T>
bool assign_min(T& a, T b) {
if (b < a) {
a = b;
return true;
}
return false;
}
template<typename T>
T square(T a) {
return a * a;
}
template<>
struct std::hash<pair<ll, ll>> {
ll operator() (pair<ll, ll> p) const {
return ((__int128)p.first * MOD + p.second) % INF64;
}
};
bool cmp(pair<ll, ll> p1, pair<ll, ll> p2) {
return p1.second < p2.second;
}
void solve() {
ll n, k;
cin >> n >> k;
vector<pair<ll, ll>> arr(n);
for (ll i = 0; i < n; i++) {
cin >> arr[i].first >> arr[i].second;
if (arr[i].second == -1) {
arr[i].second = INF32;
}
}
sort(arr.begin(), arr.end(), cmp);
vector<vector<vector<double>>> dp(n, vector<vector<double>>(n, vector<double>(n, INF32)));
for (ll i = 0; i < n; i++) {
dp[0][0][i] = arr[0].first / (double)(i + 1);
if (i > 0) {
dp[0][1][i] = arr[0].second;
}
}
for (ll i = 1; i < n; i++) {
for (ll j = 0; j < n; j++) {
for (ll k = j; k < n; k++) {
assign_min(dp[i][j][k], dp[i - 1][j][k] + arr[i].first / (double)(k + 1));
if (j && arr[i].second != INF32) {
assign_min(dp[i][j][k], dp[i - 1][j - 1][k] + arr[i].second / (double)j);
}
}
}
}
double ans = INF32;
multiset<ll> now;
ll na;
for (ll i = k; i < n; i++) {
now.insert(arr[i].first);
}
ll ns = 0;
for (ll i = k - 1; i >= 0; i--) {
for (ll j = 0; j < n; j++) {
assign_min(ans, dp[i][j][j] + ns / (double)(j + 1));
}
now.insert(arr[i].first);
ns += *now.begin();
now.erase(now.begin());
}
assign_min(ans, (double)ns);
cout << setprecision(100) << ans << '\n';
}
int main() {
if (IS_FILE) {
freopen("", "r", stdin);
freopen("", "w", stdout);
}
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
ll t = 1;
if (IS_TEST_CASES) {
cin >> t;
}
for (ll i = 0; i < t; i++) {
solve();
}
}
Compilation message
Main.cpp: In function 'void solve()':
Main.cpp:84:12: warning: unused variable 'na' [-Wunused-variable]
84 | ll na;
| ^~
Main.cpp: In function 'int main()':
Main.cpp:103:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen("", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~
Main.cpp:104:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen("", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
614 ms |
990504 KB |
Output is correct |
6 |
Correct |
516 ms |
990576 KB |
Output is correct |
7 |
Correct |
610 ms |
990576 KB |
Output is correct |
8 |
Correct |
493 ms |
990480 KB |
Output is correct |
9 |
Correct |
495 ms |
990584 KB |
Output is correct |
10 |
Correct |
628 ms |
990584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
614 ms |
990504 KB |
Output is correct |
6 |
Correct |
516 ms |
990576 KB |
Output is correct |
7 |
Correct |
610 ms |
990576 KB |
Output is correct |
8 |
Correct |
493 ms |
990480 KB |
Output is correct |
9 |
Correct |
495 ms |
990584 KB |
Output is correct |
10 |
Correct |
628 ms |
990584 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
600 ms |
990572 KB |
Output is correct |
13 |
Correct |
542 ms |
990476 KB |
Output is correct |
14 |
Correct |
505 ms |
990532 KB |
Output is correct |
15 |
Correct |
627 ms |
990528 KB |
Output is correct |
16 |
Correct |
539 ms |
990576 KB |
Output is correct |
17 |
Correct |
519 ms |
990544 KB |
Output is correct |
18 |
Correct |
594 ms |
990576 KB |
Output is correct |
19 |
Correct |
548 ms |
990580 KB |
Output is correct |
20 |
Correct |
521 ms |
990568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
476 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
424 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
328 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
0 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
476 KB |
Output is correct |
18 |
Correct |
0 ms |
336 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
336 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
336 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
424 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
6 ms |
8652 KB |
Output is correct |
42 |
Correct |
5 ms |
8532 KB |
Output is correct |
43 |
Correct |
5 ms |
8532 KB |
Output is correct |
44 |
Correct |
6 ms |
8532 KB |
Output is correct |
45 |
Correct |
5 ms |
8528 KB |
Output is correct |
46 |
Correct |
6 ms |
8532 KB |
Output is correct |
47 |
Correct |
6 ms |
8532 KB |
Output is correct |
48 |
Correct |
5 ms |
8528 KB |
Output is correct |
49 |
Correct |
6 ms |
8532 KB |
Output is correct |
50 |
Correct |
8 ms |
8532 KB |
Output is correct |
51 |
Correct |
6 ms |
8532 KB |
Output is correct |
52 |
Correct |
5 ms |
8532 KB |
Output is correct |
53 |
Correct |
6 ms |
8532 KB |
Output is correct |
54 |
Correct |
8 ms |
8648 KB |
Output is correct |
55 |
Correct |
6 ms |
8528 KB |
Output is correct |
56 |
Correct |
6 ms |
8644 KB |
Output is correct |
57 |
Correct |
6 ms |
8632 KB |
Output is correct |
58 |
Correct |
6 ms |
8532 KB |
Output is correct |
59 |
Correct |
6 ms |
8532 KB |
Output is correct |
60 |
Correct |
6 ms |
8532 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
593 ms |
990576 KB |
Output is correct |
2 |
Correct |
592 ms |
990568 KB |
Output is correct |
3 |
Correct |
572 ms |
990580 KB |
Output is correct |
4 |
Correct |
689 ms |
990496 KB |
Output is correct |
5 |
Correct |
600 ms |
990456 KB |
Output is correct |
6 |
Correct |
624 ms |
990584 KB |
Output is correct |
7 |
Correct |
625 ms |
990584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
614 ms |
990504 KB |
Output is correct |
6 |
Correct |
516 ms |
990576 KB |
Output is correct |
7 |
Correct |
610 ms |
990576 KB |
Output is correct |
8 |
Correct |
493 ms |
990480 KB |
Output is correct |
9 |
Correct |
495 ms |
990584 KB |
Output is correct |
10 |
Correct |
628 ms |
990584 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
600 ms |
990572 KB |
Output is correct |
13 |
Correct |
542 ms |
990476 KB |
Output is correct |
14 |
Correct |
505 ms |
990532 KB |
Output is correct |
15 |
Correct |
627 ms |
990528 KB |
Output is correct |
16 |
Correct |
539 ms |
990576 KB |
Output is correct |
17 |
Correct |
519 ms |
990544 KB |
Output is correct |
18 |
Correct |
594 ms |
990576 KB |
Output is correct |
19 |
Correct |
548 ms |
990580 KB |
Output is correct |
20 |
Correct |
521 ms |
990568 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
0 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
328 KB |
Output is correct |
26 |
Correct |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
1 ms |
212 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
476 KB |
Output is correct |
38 |
Correct |
0 ms |
336 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
336 KB |
Output is correct |
41 |
Correct |
0 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
0 ms |
340 KB |
Output is correct |
44 |
Correct |
0 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
336 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
0 ms |
340 KB |
Output is correct |
51 |
Correct |
0 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
336 KB |
Output is correct |
53 |
Correct |
1 ms |
344 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
1 ms |
340 KB |
Output is correct |
56 |
Correct |
1 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
424 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
6 ms |
8652 KB |
Output is correct |
62 |
Correct |
5 ms |
8532 KB |
Output is correct |
63 |
Correct |
5 ms |
8532 KB |
Output is correct |
64 |
Correct |
6 ms |
8532 KB |
Output is correct |
65 |
Correct |
5 ms |
8528 KB |
Output is correct |
66 |
Correct |
6 ms |
8532 KB |
Output is correct |
67 |
Correct |
6 ms |
8532 KB |
Output is correct |
68 |
Correct |
5 ms |
8528 KB |
Output is correct |
69 |
Correct |
6 ms |
8532 KB |
Output is correct |
70 |
Correct |
8 ms |
8532 KB |
Output is correct |
71 |
Correct |
6 ms |
8532 KB |
Output is correct |
72 |
Correct |
5 ms |
8532 KB |
Output is correct |
73 |
Correct |
6 ms |
8532 KB |
Output is correct |
74 |
Correct |
8 ms |
8648 KB |
Output is correct |
75 |
Correct |
6 ms |
8528 KB |
Output is correct |
76 |
Correct |
6 ms |
8644 KB |
Output is correct |
77 |
Correct |
6 ms |
8632 KB |
Output is correct |
78 |
Correct |
6 ms |
8532 KB |
Output is correct |
79 |
Correct |
6 ms |
8532 KB |
Output is correct |
80 |
Correct |
6 ms |
8532 KB |
Output is correct |
81 |
Correct |
593 ms |
990576 KB |
Output is correct |
82 |
Correct |
592 ms |
990568 KB |
Output is correct |
83 |
Correct |
572 ms |
990580 KB |
Output is correct |
84 |
Correct |
689 ms |
990496 KB |
Output is correct |
85 |
Correct |
600 ms |
990456 KB |
Output is correct |
86 |
Correct |
624 ms |
990584 KB |
Output is correct |
87 |
Correct |
625 ms |
990584 KB |
Output is correct |
88 |
Correct |
656 ms |
990540 KB |
Output is correct |
89 |
Correct |
581 ms |
990580 KB |
Output is correct |
90 |
Correct |
645 ms |
990496 KB |
Output is correct |
91 |
Correct |
593 ms |
990460 KB |
Output is correct |
92 |
Correct |
600 ms |
990576 KB |
Output is correct |
93 |
Correct |
591 ms |
990696 KB |
Output is correct |
94 |
Correct |
592 ms |
990580 KB |
Output is correct |
95 |
Correct |
592 ms |
990588 KB |
Output is correct |
96 |
Correct |
653 ms |
990516 KB |
Output is correct |
97 |
Correct |
590 ms |
990648 KB |
Output is correct |
98 |
Correct |
691 ms |
990580 KB |
Output is correct |
99 |
Correct |
644 ms |
990580 KB |
Output is correct |
100 |
Correct |
583 ms |
990584 KB |
Output is correct |
101 |
Correct |
625 ms |
990652 KB |
Output is correct |
102 |
Correct |
584 ms |
990468 KB |
Output is correct |
103 |
Correct |
662 ms |
990580 KB |
Output is correct |
104 |
Correct |
589 ms |
990516 KB |
Output is correct |
105 |
Correct |
611 ms |
990580 KB |
Output is correct |