#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pb push_back
#define pll pair<ll, int>
#define pii pair<int, int>
#define fi first
#define se second
using namespace std;
const int N = 5e2+5;
const int M = 8;
const int mod = 998244353;
const int base = 350;
const int inf = 1e9;
int m, n, k, t, c[N], d[N] ;
int ans, tong, b[N], a[N];
vector<int> adj[N];
string s;
int r, sz, ntime;
struct BIT
{
int n;
vector<int> fe;
BIT(){}
void init(int _n)
{
n = _n;
fe.assign(n+1, 0);
}
void add(int id, int x)
{
++id;
for(; id <= n; id += id & -id)fe[id] += x;
}
int get(int id)
{
++id;
id = min(id, n);
if(id <= 0)return 0;
int total = 0;
for(; id; id -= id & -id)total += fe[id];
return total;
}
int get(int l, int r)
{
return get(r) - get(l-1);
}
}bit[3];
void dfs(int u, int p = 0)
{
int mx = 0;
d[u] = 1;
for(int v: adj[u])
{
if(v == p || b[v])continue;
dfs(v, u);
d[u] += d[v];
mx = max(d[v], mx);
}
mx = max(mx, sz-d[u]);
if(mx*2 <= sz)r = u;
}
pii p[N];
double dp[N][N];
bool cmp(const pii& x, const pii& y)
{
if(x.se == y.se)return x.fi < y.fi;
if(x.se == -1 || y.se == -1)return x.se > y.se;
return x.se < y.se;
}
void add(double& x, double y)
{
if(x > y)x = y;
}
void sol()
{
cin >> n >> k;
for(int i = 1; i <= n; i ++)cin >> p[i].fi >> p[i].se;
sort(p+1, p+1+n, cmp);
double res = inf;
for(int i = 0; i <= k; i ++)
{
for(int j = i+1; j <= n; j ++)a[j-i] = p[j].fi;
sort(a+1, a+n-i+1);
for(int j = 1; j <= k-i; j ++)b[i] += a[j];
}
for(int x = 0; x <= k; x ++)
{
for(int j = 1; j <= x; j ++)dp[0][j] = inf;
add(res, dp[0][x]+b[0]);
for(int i = 1; i <= k; i ++)
{
for(int j = 0; j <= x; j ++)
{
dp[i][j] = inf;
add(dp[i][j], dp[i-1][j] + p[i].fi*1.0/(x+1));
if(j && p[i].se != -1)add(dp[i][j], dp[i-1][j-1] + p[i].se*1.0/j);
}
add(res, dp[i][x]+b[i]*1.0/(x+1));
}
}
cout << fixed << setprecision(5) << res;
}
int main()
{
cin.tie(0);
cout.tie(0);
ios_base::sync_with_stdio(0);
#define task "test"
if(fopen(task".inp", "r"))
{
freopen(task".inp", "r", stdin);
freopen(task".out", "w", stdout);
}
int test = 1;
//cin >> test;
while(test -- > 0)sol();
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:113:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
113 | freopen(task".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Main.cpp:114:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
114 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
13 ms |
1344 KB |
Output is correct |
8 |
Correct |
32 ms |
1748 KB |
Output is correct |
9 |
Correct |
67 ms |
2324 KB |
Output is correct |
10 |
Correct |
24 ms |
1620 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
13 ms |
1344 KB |
Output is correct |
8 |
Correct |
32 ms |
1748 KB |
Output is correct |
9 |
Correct |
67 ms |
2324 KB |
Output is correct |
10 |
Correct |
24 ms |
1620 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
940 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
5 ms |
852 KB |
Output is correct |
15 |
Correct |
51 ms |
1620 KB |
Output is correct |
16 |
Correct |
59 ms |
1716 KB |
Output is correct |
17 |
Correct |
49 ms |
1736 KB |
Output is correct |
18 |
Correct |
158 ms |
2260 KB |
Output is correct |
19 |
Correct |
147 ms |
2308 KB |
Output is correct |
20 |
Correct |
111 ms |
2432 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
356 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
352 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
352 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
344 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
356 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
344 KB |
Output is correct |
10 |
Correct |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
344 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 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 |
1 ms |
356 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
348 KB |
Output is correct |
38 |
Correct |
1 ms |
352 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
352 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
468 KB |
Output is correct |
44 |
Correct |
1 ms |
468 KB |
Output is correct |
45 |
Correct |
1 ms |
468 KB |
Output is correct |
46 |
Correct |
1 ms |
468 KB |
Output is correct |
47 |
Correct |
1 ms |
596 KB |
Output is correct |
48 |
Correct |
1 ms |
596 KB |
Output is correct |
49 |
Correct |
2 ms |
596 KB |
Output is correct |
50 |
Correct |
2 ms |
724 KB |
Output is correct |
51 |
Correct |
2 ms |
724 KB |
Output is correct |
52 |
Correct |
3 ms |
724 KB |
Output is correct |
53 |
Correct |
1 ms |
596 KB |
Output is correct |
54 |
Correct |
2 ms |
596 KB |
Output is correct |
55 |
Correct |
1 ms |
596 KB |
Output is correct |
56 |
Correct |
1 ms |
600 KB |
Output is correct |
57 |
Correct |
2 ms |
596 KB |
Output is correct |
58 |
Correct |
1 ms |
596 KB |
Output is correct |
59 |
Correct |
2 ms |
612 KB |
Output is correct |
60 |
Correct |
1 ms |
732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
2316 KB |
Output is correct |
2 |
Correct |
161 ms |
2444 KB |
Output is correct |
3 |
Correct |
178 ms |
2272 KB |
Output is correct |
4 |
Correct |
155 ms |
2288 KB |
Output is correct |
5 |
Correct |
148 ms |
2388 KB |
Output is correct |
6 |
Correct |
164 ms |
2320 KB |
Output is correct |
7 |
Correct |
167 ms |
2272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
468 KB |
Output is correct |
6 |
Correct |
3 ms |
724 KB |
Output is correct |
7 |
Correct |
13 ms |
1344 KB |
Output is correct |
8 |
Correct |
32 ms |
1748 KB |
Output is correct |
9 |
Correct |
67 ms |
2324 KB |
Output is correct |
10 |
Correct |
24 ms |
1620 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
6 ms |
940 KB |
Output is correct |
13 |
Correct |
6 ms |
852 KB |
Output is correct |
14 |
Correct |
5 ms |
852 KB |
Output is correct |
15 |
Correct |
51 ms |
1620 KB |
Output is correct |
16 |
Correct |
59 ms |
1716 KB |
Output is correct |
17 |
Correct |
49 ms |
1736 KB |
Output is correct |
18 |
Correct |
158 ms |
2260 KB |
Output is correct |
19 |
Correct |
147 ms |
2308 KB |
Output is correct |
20 |
Correct |
111 ms |
2432 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
344 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 ms |
356 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 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 |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
340 KB |
Output is correct |
40 |
Correct |
0 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
340 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
344 KB |
Output is correct |
46 |
Correct |
1 ms |
340 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
356 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 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 |
348 KB |
Output is correct |
58 |
Correct |
1 ms |
352 KB |
Output is correct |
59 |
Correct |
1 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
352 KB |
Output is correct |
61 |
Correct |
1 ms |
340 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
468 KB |
Output is correct |
64 |
Correct |
1 ms |
468 KB |
Output is correct |
65 |
Correct |
1 ms |
468 KB |
Output is correct |
66 |
Correct |
1 ms |
468 KB |
Output is correct |
67 |
Correct |
1 ms |
596 KB |
Output is correct |
68 |
Correct |
1 ms |
596 KB |
Output is correct |
69 |
Correct |
2 ms |
596 KB |
Output is correct |
70 |
Correct |
2 ms |
724 KB |
Output is correct |
71 |
Correct |
2 ms |
724 KB |
Output is correct |
72 |
Correct |
3 ms |
724 KB |
Output is correct |
73 |
Correct |
1 ms |
596 KB |
Output is correct |
74 |
Correct |
2 ms |
596 KB |
Output is correct |
75 |
Correct |
1 ms |
596 KB |
Output is correct |
76 |
Correct |
1 ms |
600 KB |
Output is correct |
77 |
Correct |
2 ms |
596 KB |
Output is correct |
78 |
Correct |
1 ms |
596 KB |
Output is correct |
79 |
Correct |
2 ms |
612 KB |
Output is correct |
80 |
Correct |
1 ms |
732 KB |
Output is correct |
81 |
Correct |
154 ms |
2316 KB |
Output is correct |
82 |
Correct |
161 ms |
2444 KB |
Output is correct |
83 |
Correct |
178 ms |
2272 KB |
Output is correct |
84 |
Correct |
155 ms |
2288 KB |
Output is correct |
85 |
Correct |
148 ms |
2388 KB |
Output is correct |
86 |
Correct |
164 ms |
2320 KB |
Output is correct |
87 |
Correct |
167 ms |
2272 KB |
Output is correct |
88 |
Correct |
3 ms |
484 KB |
Output is correct |
89 |
Correct |
2 ms |
484 KB |
Output is correct |
90 |
Correct |
6 ms |
732 KB |
Output is correct |
91 |
Correct |
6 ms |
728 KB |
Output is correct |
92 |
Correct |
24 ms |
1236 KB |
Output is correct |
93 |
Correct |
28 ms |
1460 KB |
Output is correct |
94 |
Correct |
73 ms |
1820 KB |
Output is correct |
95 |
Correct |
78 ms |
1820 KB |
Output is correct |
96 |
Correct |
128 ms |
2112 KB |
Output is correct |
97 |
Correct |
135 ms |
2132 KB |
Output is correct |
98 |
Correct |
59 ms |
1744 KB |
Output is correct |
99 |
Correct |
60 ms |
1728 KB |
Output is correct |
100 |
Correct |
65 ms |
1636 KB |
Output is correct |
101 |
Correct |
69 ms |
1728 KB |
Output is correct |
102 |
Correct |
54 ms |
1728 KB |
Output is correct |
103 |
Correct |
57 ms |
1736 KB |
Output is correct |
104 |
Correct |
58 ms |
1740 KB |
Output is correct |
105 |
Correct |
56 ms |
1724 KB |
Output is correct |