#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define ii pair<ll,ll>
#define fi first
#define se second
#define puf push_front
#define pof pop_front
#define pub push_back
#define pob pop_back
#define lb lower_bound
#define ub upper_bound
#define rep(x,s,e) for (auto x=(s)-((s)>(e));x!=(e)-((s)>(e));((s)<(e))?x++:x--)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int) (x).size()
mt19937 rng(chrono::system_clock::now().time_since_epoch().count());
int n,k;
ii arr[505];
int speed;
float memo[505][505];
float dp(int j,int k){ //we consider j A and k B
if (j+k==0) return 0;
if (memo[j][k]!=-1) return memo[j][k];
float res=1e6;
if (j) res=min(res,dp(j-1,k)+(float)arr[j+k].fi/speed);
if (k) res=min(res,dp(j,k-1)+(float)arr[j+k].se/k);
return memo[j][k]=res;
}
int best[505][505];
signed main(){
cin.tie(0);
cout.tie(0);
cin.sync_with_stdio(false);
cin>>n>>k;
rep(x,1,n+1) cin>>arr[x].fi>>arr[x].se;
int num=0;
rep(x,1,n+1){
if (arr[x].se!=-1) num++;
else arr[x].se=1e9;
}
sort(arr+1,arr+n+1,[](ii i,ii j){
return i.se<j.se;
});
vector<int> v;
rep(x,n+1,1){
v.pub(arr[x].fi);
sort(all(v));
int curr=0;
rep(y,0,sz(v)){
curr+=v[y];
best[x][y+1]=curr;
}
}
float ans=1e6;
rep(x,0,min(num,k)+1){
speed=x+1;
rep(x,0,505) rep(y,0,505) memo[x][y]=-1;
rep(y,x,k+1){
ans=min(ans,dp(y-x,x)+(float)best[y+1][k-y]/speed);
}
}
cout<<fixed<<setprecision(12)<<ans<<endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1220 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
5 ms |
3268 KB |
Output is correct |
6 |
Correct |
5 ms |
3272 KB |
Output is correct |
7 |
Correct |
5 ms |
3200 KB |
Output is correct |
8 |
Correct |
5 ms |
3276 KB |
Output is correct |
9 |
Correct |
5 ms |
3276 KB |
Output is correct |
10 |
Correct |
3 ms |
3276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1220 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
5 ms |
3268 KB |
Output is correct |
6 |
Correct |
5 ms |
3272 KB |
Output is correct |
7 |
Correct |
5 ms |
3200 KB |
Output is correct |
8 |
Correct |
5 ms |
3276 KB |
Output is correct |
9 |
Correct |
5 ms |
3276 KB |
Output is correct |
10 |
Correct |
3 ms |
3276 KB |
Output is correct |
11 |
Correct |
1 ms |
1336 KB |
Output is correct |
12 |
Correct |
36 ms |
3300 KB |
Output is correct |
13 |
Correct |
41 ms |
3300 KB |
Output is correct |
14 |
Correct |
21 ms |
3272 KB |
Output is correct |
15 |
Correct |
158 ms |
3316 KB |
Output is correct |
16 |
Correct |
108 ms |
3316 KB |
Output is correct |
17 |
Correct |
30 ms |
3264 KB |
Output is correct |
18 |
Correct |
335 ms |
3308 KB |
Output is correct |
19 |
Correct |
187 ms |
3312 KB |
Output is correct |
20 |
Correct |
47 ms |
3324 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
3 ms |
1348 KB |
Output is correct |
8 |
Correct |
3 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1352 KB |
Output is correct |
10 |
Correct |
2 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1356 KB |
Output is correct |
12 |
Correct |
2 ms |
1260 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
3 ms |
1348 KB |
Output is correct |
8 |
Correct |
3 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1352 KB |
Output is correct |
10 |
Correct |
2 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1356 KB |
Output is correct |
12 |
Correct |
2 ms |
1260 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
2 ms |
1332 KB |
Output is correct |
17 |
Correct |
2 ms |
1344 KB |
Output is correct |
18 |
Correct |
2 ms |
1344 KB |
Output is correct |
19 |
Correct |
2 ms |
1356 KB |
Output is correct |
20 |
Correct |
3 ms |
1356 KB |
Output is correct |
21 |
Correct |
4 ms |
1356 KB |
Output is correct |
22 |
Correct |
3 ms |
1352 KB |
Output is correct |
23 |
Correct |
5 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1356 KB |
Output is correct |
25 |
Correct |
3 ms |
1352 KB |
Output is correct |
26 |
Correct |
3 ms |
1352 KB |
Output is correct |
27 |
Correct |
3 ms |
1356 KB |
Output is correct |
28 |
Correct |
2 ms |
1352 KB |
Output is correct |
29 |
Correct |
4 ms |
1356 KB |
Output is correct |
30 |
Correct |
3 ms |
1356 KB |
Output is correct |
31 |
Correct |
3 ms |
1356 KB |
Output is correct |
32 |
Correct |
3 ms |
1356 KB |
Output is correct |
33 |
Correct |
2 ms |
1356 KB |
Output is correct |
34 |
Correct |
5 ms |
1356 KB |
Output is correct |
35 |
Correct |
5 ms |
1356 KB |
Output is correct |
36 |
Correct |
3 ms |
1356 KB |
Output is correct |
37 |
Correct |
4 ms |
1416 KB |
Output is correct |
38 |
Correct |
4 ms |
1412 KB |
Output is correct |
39 |
Correct |
3 ms |
1356 KB |
Output is correct |
40 |
Correct |
2 ms |
1348 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
1356 KB |
Output is correct |
2 |
Correct |
1 ms |
1356 KB |
Output is correct |
3 |
Correct |
1 ms |
1356 KB |
Output is correct |
4 |
Correct |
1 ms |
1356 KB |
Output is correct |
5 |
Correct |
2 ms |
1408 KB |
Output is correct |
6 |
Correct |
2 ms |
1356 KB |
Output is correct |
7 |
Correct |
3 ms |
1348 KB |
Output is correct |
8 |
Correct |
3 ms |
1356 KB |
Output is correct |
9 |
Correct |
2 ms |
1352 KB |
Output is correct |
10 |
Correct |
2 ms |
1356 KB |
Output is correct |
11 |
Correct |
2 ms |
1356 KB |
Output is correct |
12 |
Correct |
2 ms |
1260 KB |
Output is correct |
13 |
Correct |
2 ms |
1356 KB |
Output is correct |
14 |
Correct |
2 ms |
1228 KB |
Output is correct |
15 |
Correct |
2 ms |
1356 KB |
Output is correct |
16 |
Correct |
2 ms |
1332 KB |
Output is correct |
17 |
Correct |
2 ms |
1344 KB |
Output is correct |
18 |
Correct |
2 ms |
1344 KB |
Output is correct |
19 |
Correct |
2 ms |
1356 KB |
Output is correct |
20 |
Correct |
3 ms |
1356 KB |
Output is correct |
21 |
Correct |
4 ms |
1356 KB |
Output is correct |
22 |
Correct |
3 ms |
1352 KB |
Output is correct |
23 |
Correct |
5 ms |
1356 KB |
Output is correct |
24 |
Correct |
3 ms |
1356 KB |
Output is correct |
25 |
Correct |
3 ms |
1352 KB |
Output is correct |
26 |
Correct |
3 ms |
1352 KB |
Output is correct |
27 |
Correct |
3 ms |
1356 KB |
Output is correct |
28 |
Correct |
2 ms |
1352 KB |
Output is correct |
29 |
Correct |
4 ms |
1356 KB |
Output is correct |
30 |
Correct |
3 ms |
1356 KB |
Output is correct |
31 |
Correct |
3 ms |
1356 KB |
Output is correct |
32 |
Correct |
3 ms |
1356 KB |
Output is correct |
33 |
Correct |
2 ms |
1356 KB |
Output is correct |
34 |
Correct |
5 ms |
1356 KB |
Output is correct |
35 |
Correct |
5 ms |
1356 KB |
Output is correct |
36 |
Correct |
3 ms |
1356 KB |
Output is correct |
37 |
Correct |
4 ms |
1416 KB |
Output is correct |
38 |
Correct |
4 ms |
1412 KB |
Output is correct |
39 |
Correct |
3 ms |
1356 KB |
Output is correct |
40 |
Correct |
2 ms |
1348 KB |
Output is correct |
41 |
Correct |
3 ms |
1612 KB |
Output is correct |
42 |
Correct |
4 ms |
1612 KB |
Output is correct |
43 |
Correct |
4 ms |
1612 KB |
Output is correct |
44 |
Correct |
4 ms |
1600 KB |
Output is correct |
45 |
Correct |
7 ms |
1612 KB |
Output is correct |
46 |
Correct |
7 ms |
1612 KB |
Output is correct |
47 |
Correct |
10 ms |
1724 KB |
Output is correct |
48 |
Correct |
13 ms |
1612 KB |
Output is correct |
49 |
Correct |
11 ms |
1724 KB |
Output is correct |
50 |
Correct |
10 ms |
1724 KB |
Output is correct |
51 |
Correct |
13 ms |
1724 KB |
Output is correct |
52 |
Correct |
11 ms |
1604 KB |
Output is correct |
53 |
Correct |
8 ms |
1612 KB |
Output is correct |
54 |
Correct |
15 ms |
1612 KB |
Output is correct |
55 |
Correct |
9 ms |
1728 KB |
Output is correct |
56 |
Correct |
13 ms |
1612 KB |
Output is correct |
57 |
Correct |
12 ms |
1612 KB |
Output is correct |
58 |
Correct |
9 ms |
1612 KB |
Output is correct |
59 |
Correct |
8 ms |
1612 KB |
Output is correct |
60 |
Correct |
15 ms |
1612 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
295 ms |
3320 KB |
Output is correct |
2 |
Correct |
311 ms |
3312 KB |
Output is correct |
3 |
Correct |
264 ms |
3312 KB |
Output is correct |
4 |
Correct |
290 ms |
3276 KB |
Output is correct |
5 |
Correct |
270 ms |
3316 KB |
Output is correct |
6 |
Correct |
333 ms |
3304 KB |
Output is correct |
7 |
Correct |
386 ms |
3304 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1228 KB |
Output is correct |
2 |
Correct |
2 ms |
1220 KB |
Output is correct |
3 |
Correct |
1 ms |
1228 KB |
Output is correct |
4 |
Correct |
1 ms |
1228 KB |
Output is correct |
5 |
Correct |
5 ms |
3268 KB |
Output is correct |
6 |
Correct |
5 ms |
3272 KB |
Output is correct |
7 |
Correct |
5 ms |
3200 KB |
Output is correct |
8 |
Correct |
5 ms |
3276 KB |
Output is correct |
9 |
Correct |
5 ms |
3276 KB |
Output is correct |
10 |
Correct |
3 ms |
3276 KB |
Output is correct |
11 |
Correct |
1 ms |
1336 KB |
Output is correct |
12 |
Correct |
36 ms |
3300 KB |
Output is correct |
13 |
Correct |
41 ms |
3300 KB |
Output is correct |
14 |
Correct |
21 ms |
3272 KB |
Output is correct |
15 |
Correct |
158 ms |
3316 KB |
Output is correct |
16 |
Correct |
108 ms |
3316 KB |
Output is correct |
17 |
Correct |
30 ms |
3264 KB |
Output is correct |
18 |
Correct |
335 ms |
3308 KB |
Output is correct |
19 |
Correct |
187 ms |
3312 KB |
Output is correct |
20 |
Correct |
47 ms |
3324 KB |
Output is correct |
21 |
Correct |
2 ms |
1356 KB |
Output is correct |
22 |
Correct |
1 ms |
1356 KB |
Output is correct |
23 |
Correct |
1 ms |
1356 KB |
Output is correct |
24 |
Correct |
1 ms |
1356 KB |
Output is correct |
25 |
Correct |
2 ms |
1408 KB |
Output is correct |
26 |
Correct |
2 ms |
1356 KB |
Output is correct |
27 |
Correct |
3 ms |
1348 KB |
Output is correct |
28 |
Correct |
3 ms |
1356 KB |
Output is correct |
29 |
Correct |
2 ms |
1352 KB |
Output is correct |
30 |
Correct |
2 ms |
1356 KB |
Output is correct |
31 |
Correct |
2 ms |
1356 KB |
Output is correct |
32 |
Correct |
2 ms |
1260 KB |
Output is correct |
33 |
Correct |
2 ms |
1356 KB |
Output is correct |
34 |
Correct |
2 ms |
1228 KB |
Output is correct |
35 |
Correct |
2 ms |
1356 KB |
Output is correct |
36 |
Correct |
2 ms |
1332 KB |
Output is correct |
37 |
Correct |
2 ms |
1344 KB |
Output is correct |
38 |
Correct |
2 ms |
1344 KB |
Output is correct |
39 |
Correct |
2 ms |
1356 KB |
Output is correct |
40 |
Correct |
3 ms |
1356 KB |
Output is correct |
41 |
Correct |
4 ms |
1356 KB |
Output is correct |
42 |
Correct |
3 ms |
1352 KB |
Output is correct |
43 |
Correct |
5 ms |
1356 KB |
Output is correct |
44 |
Correct |
3 ms |
1356 KB |
Output is correct |
45 |
Correct |
3 ms |
1352 KB |
Output is correct |
46 |
Correct |
3 ms |
1352 KB |
Output is correct |
47 |
Correct |
3 ms |
1356 KB |
Output is correct |
48 |
Correct |
2 ms |
1352 KB |
Output is correct |
49 |
Correct |
4 ms |
1356 KB |
Output is correct |
50 |
Correct |
3 ms |
1356 KB |
Output is correct |
51 |
Correct |
3 ms |
1356 KB |
Output is correct |
52 |
Correct |
3 ms |
1356 KB |
Output is correct |
53 |
Correct |
2 ms |
1356 KB |
Output is correct |
54 |
Correct |
5 ms |
1356 KB |
Output is correct |
55 |
Correct |
5 ms |
1356 KB |
Output is correct |
56 |
Correct |
3 ms |
1356 KB |
Output is correct |
57 |
Correct |
4 ms |
1416 KB |
Output is correct |
58 |
Correct |
4 ms |
1412 KB |
Output is correct |
59 |
Correct |
3 ms |
1356 KB |
Output is correct |
60 |
Correct |
2 ms |
1348 KB |
Output is correct |
61 |
Correct |
3 ms |
1612 KB |
Output is correct |
62 |
Correct |
4 ms |
1612 KB |
Output is correct |
63 |
Correct |
4 ms |
1612 KB |
Output is correct |
64 |
Correct |
4 ms |
1600 KB |
Output is correct |
65 |
Correct |
7 ms |
1612 KB |
Output is correct |
66 |
Correct |
7 ms |
1612 KB |
Output is correct |
67 |
Correct |
10 ms |
1724 KB |
Output is correct |
68 |
Correct |
13 ms |
1612 KB |
Output is correct |
69 |
Correct |
11 ms |
1724 KB |
Output is correct |
70 |
Correct |
10 ms |
1724 KB |
Output is correct |
71 |
Correct |
13 ms |
1724 KB |
Output is correct |
72 |
Correct |
11 ms |
1604 KB |
Output is correct |
73 |
Correct |
8 ms |
1612 KB |
Output is correct |
74 |
Correct |
15 ms |
1612 KB |
Output is correct |
75 |
Correct |
9 ms |
1728 KB |
Output is correct |
76 |
Correct |
13 ms |
1612 KB |
Output is correct |
77 |
Correct |
12 ms |
1612 KB |
Output is correct |
78 |
Correct |
9 ms |
1612 KB |
Output is correct |
79 |
Correct |
8 ms |
1612 KB |
Output is correct |
80 |
Correct |
15 ms |
1612 KB |
Output is correct |
81 |
Correct |
295 ms |
3320 KB |
Output is correct |
82 |
Correct |
311 ms |
3312 KB |
Output is correct |
83 |
Correct |
264 ms |
3312 KB |
Output is correct |
84 |
Correct |
290 ms |
3276 KB |
Output is correct |
85 |
Correct |
270 ms |
3316 KB |
Output is correct |
86 |
Correct |
333 ms |
3304 KB |
Output is correct |
87 |
Correct |
386 ms |
3304 KB |
Output is correct |
88 |
Correct |
12 ms |
3264 KB |
Output is correct |
89 |
Correct |
12 ms |
3232 KB |
Output is correct |
90 |
Correct |
28 ms |
3304 KB |
Output is correct |
91 |
Correct |
23 ms |
3320 KB |
Output is correct |
92 |
Correct |
65 ms |
3312 KB |
Output is correct |
93 |
Correct |
60 ms |
3304 KB |
Output is correct |
94 |
Correct |
136 ms |
3312 KB |
Output is correct |
95 |
Correct |
192 ms |
3312 KB |
Output is correct |
96 |
Correct |
239 ms |
3444 KB |
Output is correct |
97 |
Correct |
267 ms |
3312 KB |
Output is correct |
98 |
Correct |
121 ms |
3308 KB |
Output is correct |
99 |
Correct |
121 ms |
3308 KB |
Output is correct |
100 |
Correct |
121 ms |
3300 KB |
Output is correct |
101 |
Correct |
146 ms |
3300 KB |
Output is correct |
102 |
Correct |
124 ms |
3244 KB |
Output is correct |
103 |
Correct |
122 ms |
3304 KB |
Output is correct |
104 |
Correct |
119 ms |
3312 KB |
Output is correct |
105 |
Correct |
146 ms |
3300 KB |
Output is correct |