#include <bits/stdc++.h>
#define speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=5e2+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
ll n,k;
pair<ldb,ldb> vt[MAX];
ldb dp[MAX][MAX];
ldb suf[MAX][MAX];
int main() {
speed;
cin>>n>>k;
for (int i=1;i<=n;i++) {
cin>>vt[i].first>>vt[i].second;
if (vt[i].second==-1) vt[i].second=INF;
}
sort(vt+1,vt+n+1,[=](pair<ldb,ldb> a,pair<ldb,ldb> b){
return a.second<b.second;
});
for (int i=1;i<=k;i++) {
suf[n+1][i]=INF;
}
suf[n+1][0]=0;
for (int i=n;i>=1;i--) {
suf[i][0]=0;
for (int j=k;j>=1;j--) {
suf[i][j]=min(suf[i+1][j-1]+vt[i].first,suf[i+1][j]);
// cout<<i<<" "<<j<<" "<<suf[i][j]<<" suf\n";
}
}
ldb ans=suf[1][k];
for (int i=1;i<=k;i++) {
for (int i=0;i<=n;i++) {
for (int j=0;j<=n;j++) dp[i][j]=INF;
}
dp[0][0]=0;
for (int j=1;j<=k;j++) {
for (int x=0;x<=i;x++) {
dp[j][x]=min(dp[j][x],dp[j-1][x]+vt[j].first/(i+1));
if (x!=0) dp[j][x]=min(dp[j][x],dp[j-1][x-1]+vt[j].second/x);
// cout<<i<<" "<<j<<" "<<x<<" "<<dp[j-1][x]+vt[j].first/(i+1)<<" "<<dp[j-1][x-1]+vt[j].second/x<<"\n";
if (x==i) {
ans=min(ans,dp[j][x]+suf[j+1][k-j]/(i+1));
// cout<<i<<" "<<j<<" "<<x<<" "<<dp[j][x]<<" "<<suf[j+1][k-j]/(i+1)<<"\n";
}
}
}
}
cout<<fixed<<setprecision(20)<<ans<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2536 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2464 KB |
Output is correct |
5 |
Correct |
53 ms |
8284 KB |
Output is correct |
6 |
Correct |
139 ms |
8440 KB |
Output is correct |
7 |
Correct |
323 ms |
8540 KB |
Output is correct |
8 |
Correct |
615 ms |
8540 KB |
Output is correct |
9 |
Correct |
1065 ms |
8540 KB |
Output is correct |
10 |
Correct |
558 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2536 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2464 KB |
Output is correct |
5 |
Correct |
53 ms |
8284 KB |
Output is correct |
6 |
Correct |
139 ms |
8440 KB |
Output is correct |
7 |
Correct |
323 ms |
8540 KB |
Output is correct |
8 |
Correct |
615 ms |
8540 KB |
Output is correct |
9 |
Correct |
1065 ms |
8540 KB |
Output is correct |
10 |
Correct |
558 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
168 ms |
8440 KB |
Output is correct |
13 |
Correct |
178 ms |
8444 KB |
Output is correct |
14 |
Correct |
168 ms |
8284 KB |
Output is correct |
15 |
Correct |
552 ms |
8540 KB |
Output is correct |
16 |
Correct |
553 ms |
8784 KB |
Output is correct |
17 |
Correct |
548 ms |
8536 KB |
Output is correct |
18 |
Correct |
1098 ms |
8540 KB |
Output is correct |
19 |
Correct |
1070 ms |
8536 KB |
Output is correct |
20 |
Correct |
1085 ms |
8540 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2508 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2508 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2516 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2392 KB |
Output is correct |
2 |
Correct |
0 ms |
2396 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2396 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
1 ms |
2396 KB |
Output is correct |
8 |
Correct |
1 ms |
2396 KB |
Output is correct |
9 |
Correct |
1 ms |
2396 KB |
Output is correct |
10 |
Correct |
1 ms |
2396 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
1 ms |
2392 KB |
Output is correct |
13 |
Correct |
1 ms |
2396 KB |
Output is correct |
14 |
Correct |
1 ms |
2396 KB |
Output is correct |
15 |
Correct |
1 ms |
2396 KB |
Output is correct |
16 |
Correct |
1 ms |
2396 KB |
Output is correct |
17 |
Correct |
1 ms |
2396 KB |
Output is correct |
18 |
Correct |
1 ms |
2396 KB |
Output is correct |
19 |
Correct |
1 ms |
2396 KB |
Output is correct |
20 |
Correct |
1 ms |
2396 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
1 ms |
2508 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2508 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2396 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2392 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2516 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
2 ms |
6492 KB |
Output is correct |
42 |
Correct |
2 ms |
6488 KB |
Output is correct |
43 |
Correct |
3 ms |
6488 KB |
Output is correct |
44 |
Correct |
3 ms |
6720 KB |
Output is correct |
45 |
Correct |
4 ms |
6724 KB |
Output is correct |
46 |
Correct |
4 ms |
6600 KB |
Output is correct |
47 |
Correct |
6 ms |
6744 KB |
Output is correct |
48 |
Correct |
5 ms |
6488 KB |
Output is correct |
49 |
Correct |
7 ms |
6492 KB |
Output is correct |
50 |
Correct |
7 ms |
6492 KB |
Output is correct |
51 |
Correct |
10 ms |
6728 KB |
Output is correct |
52 |
Correct |
10 ms |
6492 KB |
Output is correct |
53 |
Correct |
5 ms |
6492 KB |
Output is correct |
54 |
Correct |
5 ms |
6488 KB |
Output is correct |
55 |
Correct |
5 ms |
6724 KB |
Output is correct |
56 |
Correct |
5 ms |
6492 KB |
Output is correct |
57 |
Correct |
6 ms |
6492 KB |
Output is correct |
58 |
Correct |
5 ms |
6492 KB |
Output is correct |
59 |
Correct |
6 ms |
6492 KB |
Output is correct |
60 |
Correct |
5 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1121 ms |
8540 KB |
Output is correct |
2 |
Correct |
1074 ms |
8540 KB |
Output is correct |
3 |
Correct |
1068 ms |
8788 KB |
Output is correct |
4 |
Correct |
1081 ms |
8536 KB |
Output is correct |
5 |
Correct |
1073 ms |
8540 KB |
Output is correct |
6 |
Correct |
1093 ms |
8792 KB |
Output is correct |
7 |
Correct |
1100 ms |
8536 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
1 ms |
2536 KB |
Output is correct |
3 |
Correct |
1 ms |
2396 KB |
Output is correct |
4 |
Correct |
1 ms |
2464 KB |
Output is correct |
5 |
Correct |
53 ms |
8284 KB |
Output is correct |
6 |
Correct |
139 ms |
8440 KB |
Output is correct |
7 |
Correct |
323 ms |
8540 KB |
Output is correct |
8 |
Correct |
615 ms |
8540 KB |
Output is correct |
9 |
Correct |
1065 ms |
8540 KB |
Output is correct |
10 |
Correct |
558 ms |
8540 KB |
Output is correct |
11 |
Correct |
1 ms |
2396 KB |
Output is correct |
12 |
Correct |
168 ms |
8440 KB |
Output is correct |
13 |
Correct |
178 ms |
8444 KB |
Output is correct |
14 |
Correct |
168 ms |
8284 KB |
Output is correct |
15 |
Correct |
552 ms |
8540 KB |
Output is correct |
16 |
Correct |
553 ms |
8784 KB |
Output is correct |
17 |
Correct |
548 ms |
8536 KB |
Output is correct |
18 |
Correct |
1098 ms |
8540 KB |
Output is correct |
19 |
Correct |
1070 ms |
8536 KB |
Output is correct |
20 |
Correct |
1085 ms |
8540 KB |
Output is correct |
21 |
Correct |
1 ms |
2392 KB |
Output is correct |
22 |
Correct |
0 ms |
2396 KB |
Output is correct |
23 |
Correct |
1 ms |
2396 KB |
Output is correct |
24 |
Correct |
1 ms |
2396 KB |
Output is correct |
25 |
Correct |
1 ms |
2396 KB |
Output is correct |
26 |
Correct |
1 ms |
2396 KB |
Output is correct |
27 |
Correct |
1 ms |
2396 KB |
Output is correct |
28 |
Correct |
1 ms |
2396 KB |
Output is correct |
29 |
Correct |
1 ms |
2396 KB |
Output is correct |
30 |
Correct |
1 ms |
2396 KB |
Output is correct |
31 |
Correct |
1 ms |
2396 KB |
Output is correct |
32 |
Correct |
1 ms |
2392 KB |
Output is correct |
33 |
Correct |
1 ms |
2396 KB |
Output is correct |
34 |
Correct |
1 ms |
2396 KB |
Output is correct |
35 |
Correct |
1 ms |
2396 KB |
Output is correct |
36 |
Correct |
1 ms |
2396 KB |
Output is correct |
37 |
Correct |
1 ms |
2396 KB |
Output is correct |
38 |
Correct |
1 ms |
2396 KB |
Output is correct |
39 |
Correct |
1 ms |
2396 KB |
Output is correct |
40 |
Correct |
1 ms |
2396 KB |
Output is correct |
41 |
Correct |
1 ms |
2392 KB |
Output is correct |
42 |
Correct |
1 ms |
2508 KB |
Output is correct |
43 |
Correct |
1 ms |
2396 KB |
Output is correct |
44 |
Correct |
1 ms |
2396 KB |
Output is correct |
45 |
Correct |
1 ms |
2396 KB |
Output is correct |
46 |
Correct |
1 ms |
2508 KB |
Output is correct |
47 |
Correct |
1 ms |
2396 KB |
Output is correct |
48 |
Correct |
1 ms |
2396 KB |
Output is correct |
49 |
Correct |
1 ms |
2396 KB |
Output is correct |
50 |
Correct |
1 ms |
2396 KB |
Output is correct |
51 |
Correct |
1 ms |
2396 KB |
Output is correct |
52 |
Correct |
1 ms |
2396 KB |
Output is correct |
53 |
Correct |
1 ms |
2396 KB |
Output is correct |
54 |
Correct |
1 ms |
2396 KB |
Output is correct |
55 |
Correct |
1 ms |
2392 KB |
Output is correct |
56 |
Correct |
1 ms |
2396 KB |
Output is correct |
57 |
Correct |
1 ms |
2396 KB |
Output is correct |
58 |
Correct |
1 ms |
2396 KB |
Output is correct |
59 |
Correct |
1 ms |
2516 KB |
Output is correct |
60 |
Correct |
1 ms |
2396 KB |
Output is correct |
61 |
Correct |
2 ms |
6492 KB |
Output is correct |
62 |
Correct |
2 ms |
6488 KB |
Output is correct |
63 |
Correct |
3 ms |
6488 KB |
Output is correct |
64 |
Correct |
3 ms |
6720 KB |
Output is correct |
65 |
Correct |
4 ms |
6724 KB |
Output is correct |
66 |
Correct |
4 ms |
6600 KB |
Output is correct |
67 |
Correct |
6 ms |
6744 KB |
Output is correct |
68 |
Correct |
5 ms |
6488 KB |
Output is correct |
69 |
Correct |
7 ms |
6492 KB |
Output is correct |
70 |
Correct |
7 ms |
6492 KB |
Output is correct |
71 |
Correct |
10 ms |
6728 KB |
Output is correct |
72 |
Correct |
10 ms |
6492 KB |
Output is correct |
73 |
Correct |
5 ms |
6492 KB |
Output is correct |
74 |
Correct |
5 ms |
6488 KB |
Output is correct |
75 |
Correct |
5 ms |
6724 KB |
Output is correct |
76 |
Correct |
5 ms |
6492 KB |
Output is correct |
77 |
Correct |
6 ms |
6492 KB |
Output is correct |
78 |
Correct |
5 ms |
6492 KB |
Output is correct |
79 |
Correct |
6 ms |
6492 KB |
Output is correct |
80 |
Correct |
5 ms |
6492 KB |
Output is correct |
81 |
Correct |
1121 ms |
8540 KB |
Output is correct |
82 |
Correct |
1074 ms |
8540 KB |
Output is correct |
83 |
Correct |
1068 ms |
8788 KB |
Output is correct |
84 |
Correct |
1081 ms |
8536 KB |
Output is correct |
85 |
Correct |
1073 ms |
8540 KB |
Output is correct |
86 |
Correct |
1093 ms |
8792 KB |
Output is correct |
87 |
Correct |
1100 ms |
8536 KB |
Output is correct |
88 |
Correct |
56 ms |
8284 KB |
Output is correct |
89 |
Correct |
55 ms |
8440 KB |
Output is correct |
90 |
Correct |
136 ms |
8280 KB |
Output is correct |
91 |
Correct |
137 ms |
8444 KB |
Output is correct |
92 |
Correct |
328 ms |
8540 KB |
Output is correct |
93 |
Correct |
326 ms |
8540 KB |
Output is correct |
94 |
Correct |
620 ms |
8536 KB |
Output is correct |
95 |
Correct |
619 ms |
8536 KB |
Output is correct |
96 |
Correct |
871 ms |
8540 KB |
Output is correct |
97 |
Correct |
872 ms |
8548 KB |
Output is correct |
98 |
Correct |
552 ms |
8536 KB |
Output is correct |
99 |
Correct |
549 ms |
8540 KB |
Output is correct |
100 |
Correct |
548 ms |
8536 KB |
Output is correct |
101 |
Correct |
554 ms |
8784 KB |
Output is correct |
102 |
Correct |
555 ms |
8540 KB |
Output is correct |
103 |
Correct |
549 ms |
8540 KB |
Output is correct |
104 |
Correct |
548 ms |
8540 KB |
Output is correct |
105 |
Correct |
547 ms |
8540 KB |
Output is correct |