#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
#define all(X) X.begin(),X.end()
#define chmax(a,b) a=max(a,b)
#define chmin(a,b) a=min(a,b)
#ifdef local
void setio(){freopen("/Users/iantsai/Library/Mobile Documents/com~apple~CloudDocs/cpp/Empty.md","r",stdin);}
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
void setio(){}
#define debug(x...)
#endif
bool cmp(pii a,pii b){
if(a.S!=b.S)return a.S<b.S;
return a.F<b.F;
}
const int inf=2e12;
signed main(){
cout<<fixed<<setprecision(10);
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
setio();
int n,k;
cin>>n>>k;
vector<pii>vec;
vec.pb({0,0});
for(int i=0;i<n;i++){
int a,b;
cin>>a>>b;
vec.pb({a,b});
if(b==-1){
vec[i+1].S=inf;
}
}
sort(all(vec),cmp);
vector<vector<int>>suf(n+2,vector<int>(k+2,0));
for(int i=1;i<=k;i++){
multiset<int>st;
int sum=0;
for(int j=n;j>=1;j--){
st.insert(vec[j].F);
sum+=vec[j].F;
if((int)(st.size())>i){
sum-=*prev(st.end());
st.erase(prev(st.end()));
}
if((int)(st.size())==i){
suf[j][i]=sum;
}
}
}
double ans=inf;
for(int p=0;p<=k;p++){
vector<vector<double>>dp(n+1,vector<double>(p+1,inf));
dp[0][0]=0;
for(int i=1;i<=k;i++){
for(int j=0;j<=p;j++){
if(j)dp[i][j]=dp[i-1][j-1]+(double)vec[i].S/j;
dp[i][j]=min(dp[i][j],dp[i-1][j]+(double)vec[i].F/(p+1));
//cout<<i<<' '<<j<<' '<<dp[i][j]<<' '<<vec[i].F<<'\n';
if(j==p){
chmin(ans,dp[i][j]+(double)suf[i+1][k-i]/(p+1));
//cout<<i<<' '<<j<<' '<<ans<<' '<<dp[i][j]<<'\n';
}
}
}
//cout<<ans<<'\n';
}
cout<<min((double)suf[1][k],ans)<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
900 KB |
Output is correct |
6 |
Correct |
16 ms |
1712 KB |
Output is correct |
7 |
Correct |
51 ms |
2980 KB |
Output is correct |
8 |
Correct |
136 ms |
3832 KB |
Output is correct |
9 |
Correct |
240 ms |
4728 KB |
Output is correct |
10 |
Correct |
103 ms |
3472 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
900 KB |
Output is correct |
6 |
Correct |
16 ms |
1712 KB |
Output is correct |
7 |
Correct |
51 ms |
2980 KB |
Output is correct |
8 |
Correct |
136 ms |
3832 KB |
Output is correct |
9 |
Correct |
240 ms |
4728 KB |
Output is correct |
10 |
Correct |
103 ms |
3472 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
19 ms |
1904 KB |
Output is correct |
13 |
Correct |
18 ms |
1880 KB |
Output is correct |
14 |
Correct |
18 ms |
2076 KB |
Output is correct |
15 |
Correct |
106 ms |
3904 KB |
Output is correct |
16 |
Correct |
104 ms |
3640 KB |
Output is correct |
17 |
Correct |
108 ms |
3740 KB |
Output is correct |
18 |
Correct |
244 ms |
4796 KB |
Output is correct |
19 |
Correct |
268 ms |
4804 KB |
Output is correct |
20 |
Correct |
238 ms |
4796 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
452 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
0 ms |
604 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
1 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
452 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
1 ms |
348 KB |
Output is correct |
16 |
Correct |
1 ms |
348 KB |
Output is correct |
17 |
Correct |
1 ms |
348 KB |
Output is correct |
18 |
Correct |
0 ms |
348 KB |
Output is correct |
19 |
Correct |
1 ms |
348 KB |
Output is correct |
20 |
Correct |
0 ms |
348 KB |
Output is correct |
21 |
Correct |
1 ms |
348 KB |
Output is correct |
22 |
Correct |
1 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
600 KB |
Output is correct |
24 |
Correct |
1 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
1 ms |
348 KB |
Output is correct |
27 |
Correct |
1 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
600 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Correct |
1 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
452 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
456 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
348 KB |
Output is correct |
44 |
Correct |
1 ms |
356 KB |
Output is correct |
45 |
Correct |
1 ms |
360 KB |
Output is correct |
46 |
Correct |
1 ms |
356 KB |
Output is correct |
47 |
Correct |
1 ms |
616 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
2 ms |
616 KB |
Output is correct |
50 |
Correct |
2 ms |
616 KB |
Output is correct |
51 |
Correct |
2 ms |
616 KB |
Output is correct |
52 |
Correct |
2 ms |
616 KB |
Output is correct |
53 |
Correct |
1 ms |
868 KB |
Output is correct |
54 |
Correct |
1 ms |
616 KB |
Output is correct |
55 |
Correct |
1 ms |
616 KB |
Output is correct |
56 |
Correct |
1 ms |
604 KB |
Output is correct |
57 |
Correct |
1 ms |
604 KB |
Output is correct |
58 |
Correct |
1 ms |
604 KB |
Output is correct |
59 |
Correct |
2 ms |
608 KB |
Output is correct |
60 |
Correct |
1 ms |
456 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
241 ms |
5132 KB |
Output is correct |
2 |
Correct |
239 ms |
4776 KB |
Output is correct |
3 |
Correct |
248 ms |
4816 KB |
Output is correct |
4 |
Correct |
247 ms |
4760 KB |
Output is correct |
5 |
Correct |
237 ms |
4828 KB |
Output is correct |
6 |
Correct |
239 ms |
4928 KB |
Output is correct |
7 |
Correct |
254 ms |
4800 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
3 ms |
900 KB |
Output is correct |
6 |
Correct |
16 ms |
1712 KB |
Output is correct |
7 |
Correct |
51 ms |
2980 KB |
Output is correct |
8 |
Correct |
136 ms |
3832 KB |
Output is correct |
9 |
Correct |
240 ms |
4728 KB |
Output is correct |
10 |
Correct |
103 ms |
3472 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
19 ms |
1904 KB |
Output is correct |
13 |
Correct |
18 ms |
1880 KB |
Output is correct |
14 |
Correct |
18 ms |
2076 KB |
Output is correct |
15 |
Correct |
106 ms |
3904 KB |
Output is correct |
16 |
Correct |
104 ms |
3640 KB |
Output is correct |
17 |
Correct |
108 ms |
3740 KB |
Output is correct |
18 |
Correct |
244 ms |
4796 KB |
Output is correct |
19 |
Correct |
268 ms |
4804 KB |
Output is correct |
20 |
Correct |
238 ms |
4796 KB |
Output is correct |
21 |
Correct |
0 ms |
348 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
0 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
604 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
1 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
452 KB |
Output is correct |
32 |
Correct |
0 ms |
348 KB |
Output is correct |
33 |
Correct |
0 ms |
348 KB |
Output is correct |
34 |
Correct |
0 ms |
348 KB |
Output is correct |
35 |
Correct |
1 ms |
348 KB |
Output is correct |
36 |
Correct |
1 ms |
348 KB |
Output is correct |
37 |
Correct |
1 ms |
348 KB |
Output is correct |
38 |
Correct |
0 ms |
348 KB |
Output is correct |
39 |
Correct |
1 ms |
348 KB |
Output is correct |
40 |
Correct |
0 ms |
348 KB |
Output is correct |
41 |
Correct |
1 ms |
348 KB |
Output is correct |
42 |
Correct |
1 ms |
348 KB |
Output is correct |
43 |
Correct |
1 ms |
600 KB |
Output is correct |
44 |
Correct |
1 ms |
348 KB |
Output is correct |
45 |
Correct |
0 ms |
348 KB |
Output is correct |
46 |
Correct |
1 ms |
348 KB |
Output is correct |
47 |
Correct |
1 ms |
348 KB |
Output is correct |
48 |
Correct |
1 ms |
348 KB |
Output is correct |
49 |
Correct |
1 ms |
348 KB |
Output is correct |
50 |
Correct |
1 ms |
600 KB |
Output is correct |
51 |
Correct |
0 ms |
348 KB |
Output is correct |
52 |
Correct |
1 ms |
348 KB |
Output is correct |
53 |
Correct |
0 ms |
452 KB |
Output is correct |
54 |
Correct |
0 ms |
348 KB |
Output is correct |
55 |
Correct |
1 ms |
348 KB |
Output is correct |
56 |
Correct |
1 ms |
348 KB |
Output is correct |
57 |
Correct |
1 ms |
348 KB |
Output is correct |
58 |
Correct |
0 ms |
348 KB |
Output is correct |
59 |
Correct |
1 ms |
348 KB |
Output is correct |
60 |
Correct |
1 ms |
460 KB |
Output is correct |
61 |
Correct |
1 ms |
456 KB |
Output is correct |
62 |
Correct |
1 ms |
348 KB |
Output is correct |
63 |
Correct |
1 ms |
348 KB |
Output is correct |
64 |
Correct |
1 ms |
356 KB |
Output is correct |
65 |
Correct |
1 ms |
360 KB |
Output is correct |
66 |
Correct |
1 ms |
356 KB |
Output is correct |
67 |
Correct |
1 ms |
616 KB |
Output is correct |
68 |
Correct |
1 ms |
460 KB |
Output is correct |
69 |
Correct |
2 ms |
616 KB |
Output is correct |
70 |
Correct |
2 ms |
616 KB |
Output is correct |
71 |
Correct |
2 ms |
616 KB |
Output is correct |
72 |
Correct |
2 ms |
616 KB |
Output is correct |
73 |
Correct |
1 ms |
868 KB |
Output is correct |
74 |
Correct |
1 ms |
616 KB |
Output is correct |
75 |
Correct |
1 ms |
616 KB |
Output is correct |
76 |
Correct |
1 ms |
604 KB |
Output is correct |
77 |
Correct |
1 ms |
604 KB |
Output is correct |
78 |
Correct |
1 ms |
604 KB |
Output is correct |
79 |
Correct |
2 ms |
608 KB |
Output is correct |
80 |
Correct |
1 ms |
456 KB |
Output is correct |
81 |
Correct |
241 ms |
5132 KB |
Output is correct |
82 |
Correct |
239 ms |
4776 KB |
Output is correct |
83 |
Correct |
248 ms |
4816 KB |
Output is correct |
84 |
Correct |
247 ms |
4760 KB |
Output is correct |
85 |
Correct |
237 ms |
4828 KB |
Output is correct |
86 |
Correct |
239 ms |
4928 KB |
Output is correct |
87 |
Correct |
254 ms |
4800 KB |
Output is correct |
88 |
Correct |
3 ms |
940 KB |
Output is correct |
89 |
Correct |
3 ms |
904 KB |
Output is correct |
90 |
Correct |
13 ms |
1684 KB |
Output is correct |
91 |
Correct |
13 ms |
1672 KB |
Output is correct |
92 |
Correct |
52 ms |
3196 KB |
Output is correct |
93 |
Correct |
55 ms |
3192 KB |
Output is correct |
94 |
Correct |
125 ms |
3664 KB |
Output is correct |
95 |
Correct |
126 ms |
3660 KB |
Output is correct |
96 |
Correct |
186 ms |
4244 KB |
Output is correct |
97 |
Correct |
192 ms |
4440 KB |
Output is correct |
98 |
Correct |
103 ms |
3528 KB |
Output is correct |
99 |
Correct |
102 ms |
3428 KB |
Output is correct |
100 |
Correct |
104 ms |
3964 KB |
Output is correct |
101 |
Correct |
106 ms |
3744 KB |
Output is correct |
102 |
Correct |
119 ms |
3468 KB |
Output is correct |
103 |
Correct |
108 ms |
3676 KB |
Output is correct |
104 |
Correct |
108 ms |
3924 KB |
Output is correct |
105 |
Correct |
108 ms |
3596 KB |
Output is correct |