#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define V vector
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(v) int((v).size())
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef V<int> vi;
string _reset = "\u001b[0m", _yellow = "\u001b[33m", _bold = "\u001b[1m";
void DBG() { cerr << "]" << _reset << endl; }
template<class H, class...T> void DBG(H h, T ...t) {
cerr << to_string(h);
if(sizeof ...(t)) cerr << ", ";
DBG(t...);
}
#ifdef CHEISSMART
#define debug(...) cerr << _yellow << _bold << "Line(" << __LINE__ << ") -> [" << #__VA_ARGS__ << "]: [", DBG(__VA_ARGS__)
#else
#define debug(...)
#endif
const int INF = 1e9 + 7;
signed main()
{
IO_OP;
int n, k;
cin >> n >> k;
V<pi> a(n);
for(int i = 0; i < n; i++) {
cin >> a[i].S >> a[i].F;
if(a[i].F == -1) a[i].F = INF;
}
sort(ALL(a));
auto solve = [&] (int be) {
// b: 1, 1/2, 1/3..., 1/be
// a: 1/(be + 1)
V<double> dp(be + 1, INF);
dp[0] = 0;
auto go = [&] (int he) {
double ans = dp[be];
vi aux;
for(int i = he; i < n; i++)
aux.PB(a[i].S);
sort(ALL(aux));
for(int i = 0; i < k - he; i++)
ans += 1. * aux[i] / (be + 1);
return ans;
};
double ans = INF;
ans = min(ans, go(0));
for(int i = 0; i < k; i++) {
V<double> ndp(be + 1, INF);
for(int j = 0; j <= be; j++) if(dp[j] != INF) {
// a
ndp[j] = min(ndp[j], dp[j] + 1. * a[i].S / (be + 1));
// b
if(j + 1 <= be)
ndp[j + 1] = min(ndp[j + 1], dp[j] + 1. * a[i].F / (j + 1));
}
swap(dp, ndp);
ans = min(ans, go(i + 1));
}
return ans;
};
double ans = INF;
for(int be = 0; be <= k; be++)
ans = min(ans, solve(be));
cout << fixed << setprecision(10) << ans << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
14 ms |
316 KB |
Output is correct |
6 |
Correct |
83 ms |
368 KB |
Output is correct |
7 |
Correct |
291 ms |
320 KB |
Output is correct |
8 |
Correct |
619 ms |
332 KB |
Output is correct |
9 |
Correct |
1032 ms |
448 KB |
Output is correct |
10 |
Correct |
468 ms |
388 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
14 ms |
316 KB |
Output is correct |
6 |
Correct |
83 ms |
368 KB |
Output is correct |
7 |
Correct |
291 ms |
320 KB |
Output is correct |
8 |
Correct |
619 ms |
332 KB |
Output is correct |
9 |
Correct |
1032 ms |
448 KB |
Output is correct |
10 |
Correct |
468 ms |
388 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
131 ms |
504 KB |
Output is correct |
13 |
Correct |
242 ms |
472 KB |
Output is correct |
14 |
Correct |
193 ms |
332 KB |
Output is correct |
15 |
Correct |
586 ms |
452 KB |
Output is correct |
16 |
Correct |
991 ms |
448 KB |
Output is correct |
17 |
Correct |
925 ms |
376 KB |
Output is correct |
18 |
Correct |
1166 ms |
444 KB |
Output is correct |
19 |
Correct |
1796 ms |
500 KB |
Output is correct |
20 |
Correct |
1344 ms |
508 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
1 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
316 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
1 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
316 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
316 KB |
Output is correct |
24 |
Correct |
1 ms |
316 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
1 ms |
316 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
320 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
2 ms |
316 KB |
Output is correct |
42 |
Correct |
2 ms |
320 KB |
Output is correct |
43 |
Correct |
4 ms |
212 KB |
Output is correct |
44 |
Correct |
3 ms |
212 KB |
Output is correct |
45 |
Correct |
6 ms |
212 KB |
Output is correct |
46 |
Correct |
6 ms |
212 KB |
Output is correct |
47 |
Correct |
8 ms |
340 KB |
Output is correct |
48 |
Correct |
10 ms |
328 KB |
Output is correct |
49 |
Correct |
12 ms |
348 KB |
Output is correct |
50 |
Correct |
11 ms |
332 KB |
Output is correct |
51 |
Correct |
16 ms |
344 KB |
Output is correct |
52 |
Correct |
17 ms |
364 KB |
Output is correct |
53 |
Correct |
9 ms |
212 KB |
Output is correct |
54 |
Correct |
9 ms |
212 KB |
Output is correct |
55 |
Correct |
9 ms |
316 KB |
Output is correct |
56 |
Correct |
8 ms |
340 KB |
Output is correct |
57 |
Correct |
10 ms |
340 KB |
Output is correct |
58 |
Correct |
8 ms |
340 KB |
Output is correct |
59 |
Correct |
6 ms |
320 KB |
Output is correct |
60 |
Correct |
8 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2566 ms |
580 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
320 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
14 ms |
316 KB |
Output is correct |
6 |
Correct |
83 ms |
368 KB |
Output is correct |
7 |
Correct |
291 ms |
320 KB |
Output is correct |
8 |
Correct |
619 ms |
332 KB |
Output is correct |
9 |
Correct |
1032 ms |
448 KB |
Output is correct |
10 |
Correct |
468 ms |
388 KB |
Output is correct |
11 |
Correct |
0 ms |
212 KB |
Output is correct |
12 |
Correct |
131 ms |
504 KB |
Output is correct |
13 |
Correct |
242 ms |
472 KB |
Output is correct |
14 |
Correct |
193 ms |
332 KB |
Output is correct |
15 |
Correct |
586 ms |
452 KB |
Output is correct |
16 |
Correct |
991 ms |
448 KB |
Output is correct |
17 |
Correct |
925 ms |
376 KB |
Output is correct |
18 |
Correct |
1166 ms |
444 KB |
Output is correct |
19 |
Correct |
1796 ms |
500 KB |
Output is correct |
20 |
Correct |
1344 ms |
508 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
1 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
0 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
316 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
316 KB |
Output is correct |
44 |
Correct |
1 ms |
316 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
212 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
212 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
1 ms |
212 KB |
Output is correct |
52 |
Correct |
1 ms |
316 KB |
Output is correct |
53 |
Correct |
1 ms |
316 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
212 KB |
Output is correct |
56 |
Correct |
1 ms |
320 KB |
Output is correct |
57 |
Correct |
1 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
212 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
2 ms |
316 KB |
Output is correct |
62 |
Correct |
2 ms |
320 KB |
Output is correct |
63 |
Correct |
4 ms |
212 KB |
Output is correct |
64 |
Correct |
3 ms |
212 KB |
Output is correct |
65 |
Correct |
6 ms |
212 KB |
Output is correct |
66 |
Correct |
6 ms |
212 KB |
Output is correct |
67 |
Correct |
8 ms |
340 KB |
Output is correct |
68 |
Correct |
10 ms |
328 KB |
Output is correct |
69 |
Correct |
12 ms |
348 KB |
Output is correct |
70 |
Correct |
11 ms |
332 KB |
Output is correct |
71 |
Correct |
16 ms |
344 KB |
Output is correct |
72 |
Correct |
17 ms |
364 KB |
Output is correct |
73 |
Correct |
9 ms |
212 KB |
Output is correct |
74 |
Correct |
9 ms |
212 KB |
Output is correct |
75 |
Correct |
9 ms |
316 KB |
Output is correct |
76 |
Correct |
8 ms |
340 KB |
Output is correct |
77 |
Correct |
10 ms |
340 KB |
Output is correct |
78 |
Correct |
8 ms |
340 KB |
Output is correct |
79 |
Correct |
6 ms |
320 KB |
Output is correct |
80 |
Correct |
8 ms |
340 KB |
Output is correct |
81 |
Execution timed out |
2566 ms |
580 KB |
Time limit exceeded |
82 |
Halted |
0 ms |
0 KB |
- |