// 還要更強
#include<iostream>
#include<queue>
#include<set>
#include<map>
#include<iomanip>
#include<math.h>
#include<cstring>
#include<stack>
#include<string.h>
#include<random>
#include<algorithm>
#include<vector>
#define ll long long
#define DB double
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(ll i=a;i>=b;i--)
#define F first
#define S second
#define INF (int)1e9+5
#define MOD (ll)(998244353)
#define pb push_back
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define endl "\n"
using namespace std;
template<class T> using PQ=priority_queue<T,vector<T>,greater<T> >;
mt19937 rng(random_device{}());
int n,k;
vector<pair<DB,DB> > v;
bool cmp(pair<DB,DB> a,pair<DB,DB> b){
return a.S<b.S;
}
DB dp[505][505];
DB suf[505][505];
multiset<int> mst;
signed main(){
AC;
cin>>n>>k;
v.pb({0,0});
FOR(i,0,n){
int a,b; cin>>a>>b; if(b==-1) b=2000;
v.pb({a,b});
}
sort(v.begin()+1,v.end(),cmp);
REP(i,n,1){
mst.insert(v[i].F);
FOR(j,1,n-i+2){
int cnt=j;
auto it=mst.begin();
while(cnt--){
suf[i][j]+=*it; it++;
}
}
}
DB ans=1e9;
for(DB tot=1;tot<=n+1;tot++){
FOR(i,1,n+1)FOR(j,0,n+1) dp[i][j]=1e9;
//cout<<"tot="<<tot<<endl;
dp[1][0]=v[1].F/tot;
if(v[1].S!=2000) dp[1][1]=v[1].S;
if(tot==1){
ans=min(ans,dp[1][0]+suf[2][k-1]/tot);
ans=min(ans,suf[1][k]);
}
else if(tot==2) ans=min(ans,dp[1][1]+suf[2][k-1]/tot);
//cout<<"why="<<dp[1][1]+suf[2][k-1]/tot<<endl;
FOR(i,2,n+1)FOR(j,0,min(i,(int)tot)+1){
if(j&&v[i].S!=2000) dp[i][j]=min(dp[i-1][j]+v[i].F/tot,dp[i-1][j-1]+v[i].S/(DB)(j));
else dp[i][j]=dp[i-1][j]+v[i].F/tot;
if(j+1==tot) ans=min(ans,dp[i][j]+suf[i+1][k-i]/tot);
}
}
cout<<fixed<<setprecision(5);
cout<<ans<<endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
259 ms |
4296 KB |
Output is correct |
6 |
Correct |
274 ms |
4296 KB |
Output is correct |
7 |
Correct |
277 ms |
4292 KB |
Output is correct |
8 |
Correct |
271 ms |
4288 KB |
Output is correct |
9 |
Correct |
322 ms |
4292 KB |
Output is correct |
10 |
Correct |
285 ms |
4292 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
259 ms |
4296 KB |
Output is correct |
6 |
Correct |
274 ms |
4296 KB |
Output is correct |
7 |
Correct |
277 ms |
4292 KB |
Output is correct |
8 |
Correct |
271 ms |
4288 KB |
Output is correct |
9 |
Correct |
322 ms |
4292 KB |
Output is correct |
10 |
Correct |
285 ms |
4292 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
303 ms |
4228 KB |
Output is correct |
13 |
Correct |
309 ms |
4324 KB |
Output is correct |
14 |
Correct |
266 ms |
4268 KB |
Output is correct |
15 |
Correct |
315 ms |
4288 KB |
Output is correct |
16 |
Correct |
290 ms |
4292 KB |
Output is correct |
17 |
Correct |
261 ms |
4292 KB |
Output is correct |
18 |
Correct |
297 ms |
4296 KB |
Output is correct |
19 |
Correct |
269 ms |
4276 KB |
Output is correct |
20 |
Correct |
266 ms |
4196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
452 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
452 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
452 KB |
Output is correct |
25 |
Correct |
1 ms |
452 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
436 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
328 KB |
Output is correct |
3 |
Correct |
1 ms |
328 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
1 ms |
332 KB |
Output is correct |
6 |
Correct |
1 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
1 ms |
324 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
332 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
1 ms |
332 KB |
Output is correct |
13 |
Correct |
1 ms |
332 KB |
Output is correct |
14 |
Correct |
1 ms |
332 KB |
Output is correct |
15 |
Correct |
1 ms |
332 KB |
Output is correct |
16 |
Correct |
1 ms |
452 KB |
Output is correct |
17 |
Correct |
1 ms |
460 KB |
Output is correct |
18 |
Correct |
1 ms |
460 KB |
Output is correct |
19 |
Correct |
1 ms |
452 KB |
Output is correct |
20 |
Correct |
1 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
460 KB |
Output is correct |
22 |
Correct |
1 ms |
460 KB |
Output is correct |
23 |
Correct |
1 ms |
460 KB |
Output is correct |
24 |
Correct |
1 ms |
452 KB |
Output is correct |
25 |
Correct |
1 ms |
452 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
460 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
1 ms |
460 KB |
Output is correct |
30 |
Correct |
1 ms |
460 KB |
Output is correct |
31 |
Correct |
1 ms |
460 KB |
Output is correct |
32 |
Correct |
1 ms |
460 KB |
Output is correct |
33 |
Correct |
1 ms |
460 KB |
Output is correct |
34 |
Correct |
1 ms |
460 KB |
Output is correct |
35 |
Correct |
1 ms |
460 KB |
Output is correct |
36 |
Correct |
1 ms |
460 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
436 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
452 KB |
Output is correct |
41 |
Correct |
3 ms |
1100 KB |
Output is correct |
42 |
Correct |
3 ms |
1092 KB |
Output is correct |
43 |
Correct |
5 ms |
1100 KB |
Output is correct |
44 |
Correct |
3 ms |
1100 KB |
Output is correct |
45 |
Correct |
5 ms |
1100 KB |
Output is correct |
46 |
Correct |
4 ms |
1068 KB |
Output is correct |
47 |
Correct |
5 ms |
1100 KB |
Output is correct |
48 |
Correct |
5 ms |
1128 KB |
Output is correct |
49 |
Correct |
4 ms |
1100 KB |
Output is correct |
50 |
Correct |
4 ms |
1100 KB |
Output is correct |
51 |
Correct |
4 ms |
1096 KB |
Output is correct |
52 |
Correct |
4 ms |
1076 KB |
Output is correct |
53 |
Correct |
4 ms |
1100 KB |
Output is correct |
54 |
Correct |
4 ms |
1088 KB |
Output is correct |
55 |
Correct |
4 ms |
1100 KB |
Output is correct |
56 |
Correct |
3 ms |
1100 KB |
Output is correct |
57 |
Correct |
3 ms |
1100 KB |
Output is correct |
58 |
Correct |
3 ms |
1100 KB |
Output is correct |
59 |
Correct |
5 ms |
1100 KB |
Output is correct |
60 |
Correct |
3 ms |
1100 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
331 ms |
4280 KB |
Output is correct |
2 |
Correct |
321 ms |
4296 KB |
Output is correct |
3 |
Correct |
374 ms |
4292 KB |
Output is correct |
4 |
Correct |
307 ms |
4292 KB |
Output is correct |
5 |
Correct |
325 ms |
4288 KB |
Output is correct |
6 |
Correct |
285 ms |
4372 KB |
Output is correct |
7 |
Correct |
317 ms |
4296 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
332 KB |
Output is correct |
2 |
Correct |
1 ms |
332 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
1 ms |
332 KB |
Output is correct |
5 |
Correct |
259 ms |
4296 KB |
Output is correct |
6 |
Correct |
274 ms |
4296 KB |
Output is correct |
7 |
Correct |
277 ms |
4292 KB |
Output is correct |
8 |
Correct |
271 ms |
4288 KB |
Output is correct |
9 |
Correct |
322 ms |
4292 KB |
Output is correct |
10 |
Correct |
285 ms |
4292 KB |
Output is correct |
11 |
Correct |
1 ms |
332 KB |
Output is correct |
12 |
Correct |
303 ms |
4228 KB |
Output is correct |
13 |
Correct |
309 ms |
4324 KB |
Output is correct |
14 |
Correct |
266 ms |
4268 KB |
Output is correct |
15 |
Correct |
315 ms |
4288 KB |
Output is correct |
16 |
Correct |
290 ms |
4292 KB |
Output is correct |
17 |
Correct |
261 ms |
4292 KB |
Output is correct |
18 |
Correct |
297 ms |
4296 KB |
Output is correct |
19 |
Correct |
269 ms |
4276 KB |
Output is correct |
20 |
Correct |
266 ms |
4196 KB |
Output is correct |
21 |
Correct |
1 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
328 KB |
Output is correct |
23 |
Correct |
1 ms |
328 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
1 ms |
332 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
332 KB |
Output is correct |
33 |
Correct |
1 ms |
332 KB |
Output is correct |
34 |
Correct |
1 ms |
332 KB |
Output is correct |
35 |
Correct |
1 ms |
332 KB |
Output is correct |
36 |
Correct |
1 ms |
452 KB |
Output is correct |
37 |
Correct |
1 ms |
460 KB |
Output is correct |
38 |
Correct |
1 ms |
460 KB |
Output is correct |
39 |
Correct |
1 ms |
452 KB |
Output is correct |
40 |
Correct |
1 ms |
460 KB |
Output is correct |
41 |
Correct |
1 ms |
460 KB |
Output is correct |
42 |
Correct |
1 ms |
460 KB |
Output is correct |
43 |
Correct |
1 ms |
460 KB |
Output is correct |
44 |
Correct |
1 ms |
452 KB |
Output is correct |
45 |
Correct |
1 ms |
452 KB |
Output is correct |
46 |
Correct |
1 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
460 KB |
Output is correct |
48 |
Correct |
1 ms |
460 KB |
Output is correct |
49 |
Correct |
1 ms |
460 KB |
Output is correct |
50 |
Correct |
1 ms |
460 KB |
Output is correct |
51 |
Correct |
1 ms |
460 KB |
Output is correct |
52 |
Correct |
1 ms |
460 KB |
Output is correct |
53 |
Correct |
1 ms |
460 KB |
Output is correct |
54 |
Correct |
1 ms |
460 KB |
Output is correct |
55 |
Correct |
1 ms |
460 KB |
Output is correct |
56 |
Correct |
1 ms |
460 KB |
Output is correct |
57 |
Correct |
1 ms |
460 KB |
Output is correct |
58 |
Correct |
1 ms |
436 KB |
Output is correct |
59 |
Correct |
1 ms |
460 KB |
Output is correct |
60 |
Correct |
1 ms |
452 KB |
Output is correct |
61 |
Correct |
3 ms |
1100 KB |
Output is correct |
62 |
Correct |
3 ms |
1092 KB |
Output is correct |
63 |
Correct |
5 ms |
1100 KB |
Output is correct |
64 |
Correct |
3 ms |
1100 KB |
Output is correct |
65 |
Correct |
5 ms |
1100 KB |
Output is correct |
66 |
Correct |
4 ms |
1068 KB |
Output is correct |
67 |
Correct |
5 ms |
1100 KB |
Output is correct |
68 |
Correct |
5 ms |
1128 KB |
Output is correct |
69 |
Correct |
4 ms |
1100 KB |
Output is correct |
70 |
Correct |
4 ms |
1100 KB |
Output is correct |
71 |
Correct |
4 ms |
1096 KB |
Output is correct |
72 |
Correct |
4 ms |
1076 KB |
Output is correct |
73 |
Correct |
4 ms |
1100 KB |
Output is correct |
74 |
Correct |
4 ms |
1088 KB |
Output is correct |
75 |
Correct |
4 ms |
1100 KB |
Output is correct |
76 |
Correct |
3 ms |
1100 KB |
Output is correct |
77 |
Correct |
3 ms |
1100 KB |
Output is correct |
78 |
Correct |
3 ms |
1100 KB |
Output is correct |
79 |
Correct |
5 ms |
1100 KB |
Output is correct |
80 |
Correct |
3 ms |
1100 KB |
Output is correct |
81 |
Correct |
331 ms |
4280 KB |
Output is correct |
82 |
Correct |
321 ms |
4296 KB |
Output is correct |
83 |
Correct |
374 ms |
4292 KB |
Output is correct |
84 |
Correct |
307 ms |
4292 KB |
Output is correct |
85 |
Correct |
325 ms |
4288 KB |
Output is correct |
86 |
Correct |
285 ms |
4372 KB |
Output is correct |
87 |
Correct |
317 ms |
4296 KB |
Output is correct |
88 |
Correct |
282 ms |
4296 KB |
Output is correct |
89 |
Correct |
312 ms |
4300 KB |
Output is correct |
90 |
Correct |
276 ms |
4296 KB |
Output is correct |
91 |
Correct |
294 ms |
4352 KB |
Output is correct |
92 |
Correct |
274 ms |
4296 KB |
Output is correct |
93 |
Correct |
292 ms |
4332 KB |
Output is correct |
94 |
Correct |
270 ms |
4296 KB |
Output is correct |
95 |
Correct |
286 ms |
4224 KB |
Output is correct |
96 |
Correct |
288 ms |
4408 KB |
Output is correct |
97 |
Correct |
297 ms |
4292 KB |
Output is correct |
98 |
Correct |
290 ms |
4412 KB |
Output is correct |
99 |
Correct |
292 ms |
4188 KB |
Output is correct |
100 |
Correct |
293 ms |
4296 KB |
Output is correct |
101 |
Correct |
306 ms |
4336 KB |
Output is correct |
102 |
Correct |
312 ms |
4360 KB |
Output is correct |
103 |
Correct |
295 ms |
4204 KB |
Output is correct |
104 |
Correct |
308 ms |
4292 KB |
Output is correct |
105 |
Correct |
270 ms |
4208 KB |
Output is correct |