#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(),x.end()
#define int long long
int INF=1e9;
signed main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
int n;cin>>n;
int k;cin>>k;
vector<pair<int,int>> v(n+1);
for(int i=1;i<=n;i++){
cin>>v[i].first>>v[i].second;
if(v[i].second==-1){
v[i].second=INF;
}
}
sort(all(v),[&](pair<int,int> a,pair<int,int> b){
return a.second<b.second;
});
double ans=INF;
for(int t=0;t<k;t++){
vector<vector<double>> dp(t+1,vector<double>(n+1,INF));
dp[0][0]=0;
for(int i=1;i<=n;i++){
dp[0][i]=dp[0][i-1]+(double)v[i].first/(t+1);
}
for(int i=1;i<=t;i++){
for(int j=1;j<=n;j++){
dp[i][j]=min(dp[i][j],dp[i-1][j-1]+(double)v[j].second/i);
dp[i][j]=min(dp[i][j],dp[i][j-1]+(double)v[j].first/(t+1));
}
}
double total=0;
double mn=INF;
priority_queue<double,vector<double>,greater<double>> pq;
for(int i=n;i>k;i--){
pq.push((double)v[i].first/(t+1));
}
for(int i=k;i>=t;i--){
mn=min(mn,dp[t][i]+total);
pq.push((double)v[i].first/(t+1));
while(pq.size()>n-k){
total+=pq.top();
pq.pop();
}
}
ans=min(ans,mn);
}
cout<<setprecision(9)<<ans<<endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:44:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<double, std::vector<double>, std::greater<double> >::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
44 | while(pq.size()>n-k){
| ~~~~~~~~~^~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
540 KB |
Output is correct |
6 |
Correct |
24 ms |
1024 KB |
Output is correct |
7 |
Correct |
101 ms |
1728 KB |
Output is correct |
8 |
Correct |
223 ms |
1880 KB |
Output is correct |
9 |
Correct |
398 ms |
2300 KB |
Output is correct |
10 |
Correct |
199 ms |
1884 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
540 KB |
Output is correct |
6 |
Correct |
24 ms |
1024 KB |
Output is correct |
7 |
Correct |
101 ms |
1728 KB |
Output is correct |
8 |
Correct |
223 ms |
1880 KB |
Output is correct |
9 |
Correct |
398 ms |
2300 KB |
Output is correct |
10 |
Correct |
199 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
36 ms |
912 KB |
Output is correct |
13 |
Correct |
36 ms |
892 KB |
Output is correct |
14 |
Correct |
35 ms |
916 KB |
Output is correct |
15 |
Correct |
199 ms |
1760 KB |
Output is correct |
16 |
Correct |
226 ms |
1848 KB |
Output is correct |
17 |
Correct |
202 ms |
1752 KB |
Output is correct |
18 |
Correct |
417 ms |
2340 KB |
Output is correct |
19 |
Correct |
414 ms |
2432 KB |
Output is correct |
20 |
Correct |
401 ms |
2392 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
1 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
320 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
0 ms |
212 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
212 KB |
Output is correct |
13 |
Correct |
0 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
212 KB |
Output is correct |
15 |
Correct |
1 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
0 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
212 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
1 ms |
212 KB |
Output is correct |
26 |
Correct |
1 ms |
320 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
316 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
0 ms |
324 KB |
Output is correct |
32 |
Correct |
1 ms |
316 KB |
Output is correct |
33 |
Correct |
1 ms |
324 KB |
Output is correct |
34 |
Correct |
1 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
316 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
320 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
1 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
320 KB |
Output is correct |
42 |
Correct |
1 ms |
340 KB |
Output is correct |
43 |
Correct |
1 ms |
340 KB |
Output is correct |
44 |
Correct |
1 ms |
340 KB |
Output is correct |
45 |
Correct |
1 ms |
340 KB |
Output is correct |
46 |
Correct |
1 ms |
320 KB |
Output is correct |
47 |
Correct |
2 ms |
340 KB |
Output is correct |
48 |
Correct |
2 ms |
340 KB |
Output is correct |
49 |
Correct |
2 ms |
320 KB |
Output is correct |
50 |
Correct |
3 ms |
320 KB |
Output is correct |
51 |
Correct |
3 ms |
340 KB |
Output is correct |
52 |
Correct |
3 ms |
340 KB |
Output is correct |
53 |
Correct |
2 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
2 ms |
324 KB |
Output is correct |
56 |
Correct |
2 ms |
340 KB |
Output is correct |
57 |
Correct |
2 ms |
340 KB |
Output is correct |
58 |
Correct |
2 ms |
340 KB |
Output is correct |
59 |
Correct |
2 ms |
340 KB |
Output is correct |
60 |
Correct |
2 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
424 ms |
2500 KB |
Output is correct |
2 |
Correct |
416 ms |
2332 KB |
Output is correct |
3 |
Correct |
419 ms |
2344 KB |
Output is correct |
4 |
Correct |
405 ms |
2368 KB |
Output is correct |
5 |
Correct |
422 ms |
2440 KB |
Output is correct |
6 |
Correct |
412 ms |
2344 KB |
Output is correct |
7 |
Correct |
409 ms |
2348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 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 |
212 KB |
Output is correct |
5 |
Correct |
5 ms |
540 KB |
Output is correct |
6 |
Correct |
24 ms |
1024 KB |
Output is correct |
7 |
Correct |
101 ms |
1728 KB |
Output is correct |
8 |
Correct |
223 ms |
1880 KB |
Output is correct |
9 |
Correct |
398 ms |
2300 KB |
Output is correct |
10 |
Correct |
199 ms |
1884 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
36 ms |
912 KB |
Output is correct |
13 |
Correct |
36 ms |
892 KB |
Output is correct |
14 |
Correct |
35 ms |
916 KB |
Output is correct |
15 |
Correct |
199 ms |
1760 KB |
Output is correct |
16 |
Correct |
226 ms |
1848 KB |
Output is correct |
17 |
Correct |
202 ms |
1752 KB |
Output is correct |
18 |
Correct |
417 ms |
2340 KB |
Output is correct |
19 |
Correct |
414 ms |
2432 KB |
Output is correct |
20 |
Correct |
401 ms |
2392 KB |
Output is correct |
21 |
Correct |
0 ms |
212 KB |
Output is correct |
22 |
Correct |
0 ms |
212 KB |
Output is correct |
23 |
Correct |
0 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
212 KB |
Output is correct |
25 |
Correct |
0 ms |
212 KB |
Output is correct |
26 |
Correct |
0 ms |
212 KB |
Output is correct |
27 |
Correct |
1 ms |
212 KB |
Output is correct |
28 |
Correct |
0 ms |
212 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
0 ms |
212 KB |
Output is correct |
31 |
Correct |
1 ms |
212 KB |
Output is correct |
32 |
Correct |
1 ms |
212 KB |
Output is correct |
33 |
Correct |
0 ms |
212 KB |
Output is correct |
34 |
Correct |
0 ms |
212 KB |
Output is correct |
35 |
Correct |
1 ms |
212 KB |
Output is correct |
36 |
Correct |
1 ms |
212 KB |
Output is correct |
37 |
Correct |
0 ms |
212 KB |
Output is correct |
38 |
Correct |
1 ms |
212 KB |
Output is correct |
39 |
Correct |
1 ms |
212 KB |
Output is correct |
40 |
Correct |
0 ms |
212 KB |
Output is correct |
41 |
Correct |
1 ms |
212 KB |
Output is correct |
42 |
Correct |
1 ms |
212 KB |
Output is correct |
43 |
Correct |
1 ms |
212 KB |
Output is correct |
44 |
Correct |
1 ms |
212 KB |
Output is correct |
45 |
Correct |
1 ms |
212 KB |
Output is correct |
46 |
Correct |
1 ms |
320 KB |
Output is correct |
47 |
Correct |
1 ms |
212 KB |
Output is correct |
48 |
Correct |
1 ms |
316 KB |
Output is correct |
49 |
Correct |
1 ms |
212 KB |
Output is correct |
50 |
Correct |
1 ms |
212 KB |
Output is correct |
51 |
Correct |
0 ms |
324 KB |
Output is correct |
52 |
Correct |
1 ms |
316 KB |
Output is correct |
53 |
Correct |
1 ms |
324 KB |
Output is correct |
54 |
Correct |
1 ms |
212 KB |
Output is correct |
55 |
Correct |
1 ms |
316 KB |
Output is correct |
56 |
Correct |
1 ms |
212 KB |
Output is correct |
57 |
Correct |
0 ms |
212 KB |
Output is correct |
58 |
Correct |
1 ms |
320 KB |
Output is correct |
59 |
Correct |
1 ms |
212 KB |
Output is correct |
60 |
Correct |
1 ms |
212 KB |
Output is correct |
61 |
Correct |
1 ms |
320 KB |
Output is correct |
62 |
Correct |
1 ms |
340 KB |
Output is correct |
63 |
Correct |
1 ms |
340 KB |
Output is correct |
64 |
Correct |
1 ms |
340 KB |
Output is correct |
65 |
Correct |
1 ms |
340 KB |
Output is correct |
66 |
Correct |
1 ms |
320 KB |
Output is correct |
67 |
Correct |
2 ms |
340 KB |
Output is correct |
68 |
Correct |
2 ms |
340 KB |
Output is correct |
69 |
Correct |
2 ms |
320 KB |
Output is correct |
70 |
Correct |
3 ms |
320 KB |
Output is correct |
71 |
Correct |
3 ms |
340 KB |
Output is correct |
72 |
Correct |
3 ms |
340 KB |
Output is correct |
73 |
Correct |
2 ms |
340 KB |
Output is correct |
74 |
Correct |
1 ms |
340 KB |
Output is correct |
75 |
Correct |
2 ms |
324 KB |
Output is correct |
76 |
Correct |
2 ms |
340 KB |
Output is correct |
77 |
Correct |
2 ms |
340 KB |
Output is correct |
78 |
Correct |
2 ms |
340 KB |
Output is correct |
79 |
Correct |
2 ms |
340 KB |
Output is correct |
80 |
Correct |
2 ms |
340 KB |
Output is correct |
81 |
Correct |
424 ms |
2500 KB |
Output is correct |
82 |
Correct |
416 ms |
2332 KB |
Output is correct |
83 |
Correct |
419 ms |
2344 KB |
Output is correct |
84 |
Correct |
405 ms |
2368 KB |
Output is correct |
85 |
Correct |
422 ms |
2440 KB |
Output is correct |
86 |
Correct |
412 ms |
2344 KB |
Output is correct |
87 |
Correct |
409 ms |
2348 KB |
Output is correct |
88 |
Correct |
4 ms |
516 KB |
Output is correct |
89 |
Correct |
4 ms |
544 KB |
Output is correct |
90 |
Correct |
24 ms |
832 KB |
Output is correct |
91 |
Correct |
26 ms |
948 KB |
Output is correct |
92 |
Correct |
100 ms |
1300 KB |
Output is correct |
93 |
Correct |
99 ms |
1328 KB |
Output is correct |
94 |
Correct |
247 ms |
1880 KB |
Output is correct |
95 |
Correct |
225 ms |
1796 KB |
Output is correct |
96 |
Correct |
325 ms |
2248 KB |
Output is correct |
97 |
Correct |
323 ms |
2168 KB |
Output is correct |
98 |
Correct |
195 ms |
1816 KB |
Output is correct |
99 |
Correct |
198 ms |
1812 KB |
Output is correct |
100 |
Correct |
200 ms |
1800 KB |
Output is correct |
101 |
Correct |
195 ms |
1732 KB |
Output is correct |
102 |
Correct |
198 ms |
1792 KB |
Output is correct |
103 |
Correct |
195 ms |
1848 KB |
Output is correct |
104 |
Correct |
207 ms |
1684 KB |
Output is correct |
105 |
Correct |
201 ms |
1812 KB |
Output is correct |