#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
bool cmp(pair<int,int> a , pair<int,int> b){
if(a.vs == -1)return 0;
if(b.vs == -1)return 1;
if(a.vs != b.vs)return a.vs < b.vs;
return a.vf < b.vf;
}
const int N = 503;
int pre[N][N];
vector<pair<int,int>> v;
double dp[N][N];
int n , k;
double find(int x){
if(x == 0)return pre[0][k-1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++)dp[i][j] = 1e9;
}
dp[0][0] = 0.0;
double res = 1e9;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(i,x); j++){
if(v[i-1].vs == -1){
goto h;
}
if(j == 0){
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
continue;
}
if(j == x){
int rem = k - i;
res = min(res , dp[i-1][j-1] + (double)v[i-1].vs/(double)j + (rem > 0 ? (double)pre[i][rem-1]/(double)(x+1) : 0));
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
}
else {
dp[i][j] = min(dp[i-1][j-1] + (double)v[i-1].vs/(double)j , dp[i-1][j] + (double)v[i-1].vf/(double)(x+1));
}
}
}
h:
return res;
}
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i = 0; i < n; i++){
int x , y;
cin >> x >> y;
v.pb(mp(x,y));
if(y != -1)cnt++;
}
sort(all(v), cmp);
vector<int> tp;
for(int i = n - 1; i >= 0; i--){
tp.pb(v[i].vf);
sv(tp);
int cur = 0 , sum = 0;
for(int j = i; j < n; j++){
sum += tp[cur];
pre[i][cur] = sum;
cur++;
}
}
if(cnt == 0){
cout << pre[0][k-1] << '\n';
return;
}
double ans = 1e9;
for(int i = 0; i <= cnt; i++){
ans = min(ans , find(i));
}
cout << setprecision(10) << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1232 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1208 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1232 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1208 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
206 ms |
3284 KB |
Output is correct |
13 |
Correct |
71 ms |
3276 KB |
Output is correct |
14 |
Correct |
14 ms |
3284 KB |
Output is correct |
15 |
Correct |
229 ms |
3284 KB |
Output is correct |
16 |
Correct |
62 ms |
3284 KB |
Output is correct |
17 |
Correct |
15 ms |
3284 KB |
Output is correct |
18 |
Correct |
209 ms |
3268 KB |
Output is correct |
19 |
Correct |
65 ms |
3284 KB |
Output is correct |
20 |
Correct |
13 ms |
3284 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 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 |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 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 |
1 ms |
340 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 |
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 |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
352 KB |
Output is correct |
7 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
340 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
0 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
0 ms |
340 KB |
Output is correct |
19 |
Correct |
0 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 |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
27 |
Correct |
0 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 |
1 ms |
340 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 |
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 |
0 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
2 ms |
852 KB |
Output is correct |
42 |
Correct |
2 ms |
852 KB |
Output is correct |
43 |
Correct |
3 ms |
852 KB |
Output is correct |
44 |
Correct |
2 ms |
852 KB |
Output is correct |
45 |
Correct |
3 ms |
852 KB |
Output is correct |
46 |
Correct |
2 ms |
852 KB |
Output is correct |
47 |
Correct |
3 ms |
856 KB |
Output is correct |
48 |
Correct |
2 ms |
852 KB |
Output is correct |
49 |
Correct |
2 ms |
852 KB |
Output is correct |
50 |
Correct |
2 ms |
852 KB |
Output is correct |
51 |
Correct |
3 ms |
844 KB |
Output is correct |
52 |
Correct |
2 ms |
852 KB |
Output is correct |
53 |
Correct |
2 ms |
852 KB |
Output is correct |
54 |
Correct |
2 ms |
852 KB |
Output is correct |
55 |
Correct |
4 ms |
852 KB |
Output is correct |
56 |
Correct |
3 ms |
852 KB |
Output is correct |
57 |
Correct |
3 ms |
852 KB |
Output is correct |
58 |
Correct |
3 ms |
852 KB |
Output is correct |
59 |
Correct |
2 ms |
852 KB |
Output is correct |
60 |
Correct |
2 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
200 ms |
3284 KB |
Output is correct |
2 |
Correct |
203 ms |
3284 KB |
Output is correct |
3 |
Correct |
223 ms |
3284 KB |
Output is correct |
4 |
Correct |
199 ms |
3284 KB |
Output is correct |
5 |
Correct |
223 ms |
3284 KB |
Output is correct |
6 |
Correct |
218 ms |
3284 KB |
Output is correct |
7 |
Correct |
220 ms |
3264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 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 |
340 KB |
Output is correct |
5 |
Correct |
3 ms |
1236 KB |
Output is correct |
6 |
Correct |
3 ms |
1232 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
5 ms |
1208 KB |
Output is correct |
9 |
Correct |
3 ms |
1236 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
206 ms |
3284 KB |
Output is correct |
13 |
Correct |
71 ms |
3276 KB |
Output is correct |
14 |
Correct |
14 ms |
3284 KB |
Output is correct |
15 |
Correct |
229 ms |
3284 KB |
Output is correct |
16 |
Correct |
62 ms |
3284 KB |
Output is correct |
17 |
Correct |
15 ms |
3284 KB |
Output is correct |
18 |
Correct |
209 ms |
3268 KB |
Output is correct |
19 |
Correct |
65 ms |
3284 KB |
Output is correct |
20 |
Correct |
13 ms |
3284 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
340 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
0 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
352 KB |
Output is correct |
27 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
340 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
0 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
0 ms |
340 KB |
Output is correct |
39 |
Correct |
0 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 |
0 ms |
340 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 |
0 ms |
340 KB |
Output is correct |
47 |
Correct |
0 ms |
340 KB |
Output is correct |
48 |
Correct |
0 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 |
340 KB |
Output is correct |
52 |
Correct |
0 ms |
340 KB |
Output is correct |
53 |
Correct |
0 ms |
340 KB |
Output is correct |
54 |
Correct |
0 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 |
0 ms |
340 KB |
Output is correct |
58 |
Correct |
0 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
2 ms |
852 KB |
Output is correct |
62 |
Correct |
2 ms |
852 KB |
Output is correct |
63 |
Correct |
3 ms |
852 KB |
Output is correct |
64 |
Correct |
2 ms |
852 KB |
Output is correct |
65 |
Correct |
3 ms |
852 KB |
Output is correct |
66 |
Correct |
2 ms |
852 KB |
Output is correct |
67 |
Correct |
3 ms |
856 KB |
Output is correct |
68 |
Correct |
2 ms |
852 KB |
Output is correct |
69 |
Correct |
2 ms |
852 KB |
Output is correct |
70 |
Correct |
2 ms |
852 KB |
Output is correct |
71 |
Correct |
3 ms |
844 KB |
Output is correct |
72 |
Correct |
2 ms |
852 KB |
Output is correct |
73 |
Correct |
2 ms |
852 KB |
Output is correct |
74 |
Correct |
2 ms |
852 KB |
Output is correct |
75 |
Correct |
4 ms |
852 KB |
Output is correct |
76 |
Correct |
3 ms |
852 KB |
Output is correct |
77 |
Correct |
3 ms |
852 KB |
Output is correct |
78 |
Correct |
3 ms |
852 KB |
Output is correct |
79 |
Correct |
2 ms |
852 KB |
Output is correct |
80 |
Correct |
2 ms |
852 KB |
Output is correct |
81 |
Correct |
200 ms |
3284 KB |
Output is correct |
82 |
Correct |
203 ms |
3284 KB |
Output is correct |
83 |
Correct |
223 ms |
3284 KB |
Output is correct |
84 |
Correct |
199 ms |
3284 KB |
Output is correct |
85 |
Correct |
223 ms |
3284 KB |
Output is correct |
86 |
Correct |
218 ms |
3284 KB |
Output is correct |
87 |
Correct |
220 ms |
3264 KB |
Output is correct |
88 |
Correct |
211 ms |
3272 KB |
Output is correct |
89 |
Correct |
200 ms |
3284 KB |
Output is correct |
90 |
Correct |
212 ms |
3284 KB |
Output is correct |
91 |
Correct |
209 ms |
3284 KB |
Output is correct |
92 |
Correct |
222 ms |
3284 KB |
Output is correct |
93 |
Correct |
201 ms |
3284 KB |
Output is correct |
94 |
Correct |
202 ms |
3284 KB |
Output is correct |
95 |
Correct |
204 ms |
3284 KB |
Output is correct |
96 |
Correct |
207 ms |
3284 KB |
Output is correct |
97 |
Correct |
200 ms |
3284 KB |
Output is correct |
98 |
Correct |
206 ms |
3284 KB |
Output is correct |
99 |
Correct |
203 ms |
3284 KB |
Output is correct |
100 |
Correct |
202 ms |
3284 KB |
Output is correct |
101 |
Correct |
212 ms |
3288 KB |
Output is correct |
102 |
Correct |
232 ms |
3284 KB |
Output is correct |
103 |
Correct |
203 ms |
3284 KB |
Output is correct |
104 |
Correct |
209 ms |
3284 KB |
Output is correct |
105 |
Correct |
200 ms |
3268 KB |
Output is correct |