#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
bool cmp(pair<int,int> a , pair<int,int> b){
if(a.vs == -1)return 0;
if(b.vs == -1)return 1;
if(a.vs != b.vs)return a.vs < b.vs;
return a.vf < b.vf;
}
const int N = 503;
int pre[N][N];
vector<pair<int,int>> v;
double dp[N][N];
int n , k;
double find(int x){
if(x == 0)return pre[0][k-1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++)dp[i][j] = 1e9;
}
dp[0][0] = 0.0;
double res = 1e9;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(i,x); j++){
if(v[i-1].vs == -1){
goto h;
}
if(j == 0){
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
continue;
}
if(j == x){
int rem = k - i;
res = min(res , dp[i-1][j-1] + (double)v[i-1].vs/(double)j + (rem > 0 ? (double)pre[i][rem-1]/(double)(x+1) : 0));
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
}
else {
dp[i][j] = min(dp[i-1][j-1] + (double)v[i-1].vs/(double)j , dp[i-1][j] + (double)v[i-1].vf/(double)(x+1));
}
}
}
h:
return res;
}
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i = 0; i < n; i++){
int x , y;
cin >> x >> y;
v.pb(mp(x,y));
if(y != -1)cnt++;
}
sort(all(v), cmp);
vector<int> tp;
for(int i = n - 1; i >= 0; i--){
tp.pb(v[i].vf);
sv(tp);
int cur = 0 , sum = 0;
for(int j = i; j < n; j++){
sum += tp[cur];
pre[i][cur] = sum;
cur++;
}
}
int l = 1 , r = min(k , cnt);
if(cnt == 0){
cout << pre[0][k-1] << '\n';
return;
}
double ans = 1e9;
while(l <= r){
int mid = (l + r)/2;
double x = find(mid) , y = find(mid - 1);
ans = min(ans , min(x , y));
//cout << mid << ' ' << x << ' ' << y << '\n';
if(x > y){
r = mid - 1;
}
else l = mid + 1;
}
cout << setprecision(10) << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
9 |
Correct |
7 ms |
1316 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 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 |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
9 |
Correct |
7 ms |
1316 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
20 ms |
3172 KB |
Output is correct |
13 |
Correct |
7 ms |
3284 KB |
Output is correct |
14 |
Correct |
6 ms |
3296 KB |
Output is correct |
15 |
Correct |
14 ms |
3292 KB |
Output is correct |
16 |
Correct |
9 ms |
3296 KB |
Output is correct |
17 |
Correct |
7 ms |
3284 KB |
Output is correct |
18 |
Correct |
16 ms |
3284 KB |
Output is correct |
19 |
Correct |
10 ms |
3284 KB |
Output is correct |
20 |
Correct |
8 ms |
3284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
360 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
336 KB |
Output is correct |
9 |
Correct |
1 ms |
332 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
0 ms |
344 KB |
Output is correct |
12 |
Correct |
1 ms |
340 KB |
Output is correct |
13 |
Correct |
0 ms |
344 KB |
Output is correct |
14 |
Correct |
0 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
0 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
340 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
336 KB |
Output is correct |
20 |
Correct |
1 ms |
340 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
1 ms |
336 KB |
Output is correct |
23 |
Correct |
1 ms |
360 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
1 ms |
340 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
1 ms |
340 KB |
Output is correct |
34 |
Correct |
1 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
344 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
0 ms |
340 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
852 KB |
Output is correct |
42 |
Correct |
1 ms |
852 KB |
Output is correct |
43 |
Correct |
1 ms |
880 KB |
Output is correct |
44 |
Correct |
1 ms |
852 KB |
Output is correct |
45 |
Correct |
1 ms |
852 KB |
Output is correct |
46 |
Correct |
1 ms |
852 KB |
Output is correct |
47 |
Correct |
1 ms |
852 KB |
Output is correct |
48 |
Correct |
1 ms |
848 KB |
Output is correct |
49 |
Correct |
1 ms |
852 KB |
Output is correct |
50 |
Correct |
1 ms |
852 KB |
Output is correct |
51 |
Correct |
1 ms |
852 KB |
Output is correct |
52 |
Correct |
1 ms |
852 KB |
Output is correct |
53 |
Correct |
1 ms |
852 KB |
Output is correct |
54 |
Correct |
1 ms |
852 KB |
Output is correct |
55 |
Correct |
1 ms |
852 KB |
Output is correct |
56 |
Correct |
1 ms |
852 KB |
Output is correct |
57 |
Correct |
1 ms |
852 KB |
Output is correct |
58 |
Correct |
1 ms |
852 KB |
Output is correct |
59 |
Correct |
1 ms |
848 KB |
Output is correct |
60 |
Correct |
1 ms |
852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
13 ms |
3296 KB |
Output is correct |
2 |
Correct |
16 ms |
3172 KB |
Output is correct |
3 |
Correct |
13 ms |
3284 KB |
Output is correct |
4 |
Correct |
14 ms |
3300 KB |
Output is correct |
5 |
Correct |
14 ms |
3300 KB |
Output is correct |
6 |
Correct |
11 ms |
3332 KB |
Output is correct |
7 |
Correct |
14 ms |
3284 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 |
0 ms |
336 KB |
Output is correct |
5 |
Correct |
4 ms |
1236 KB |
Output is correct |
6 |
Correct |
4 ms |
1236 KB |
Output is correct |
7 |
Correct |
3 ms |
1236 KB |
Output is correct |
8 |
Correct |
3 ms |
1236 KB |
Output is correct |
9 |
Correct |
7 ms |
1316 KB |
Output is correct |
10 |
Correct |
2 ms |
1236 KB |
Output is correct |
11 |
Correct |
0 ms |
340 KB |
Output is correct |
12 |
Correct |
20 ms |
3172 KB |
Output is correct |
13 |
Correct |
7 ms |
3284 KB |
Output is correct |
14 |
Correct |
6 ms |
3296 KB |
Output is correct |
15 |
Correct |
14 ms |
3292 KB |
Output is correct |
16 |
Correct |
9 ms |
3296 KB |
Output is correct |
17 |
Correct |
7 ms |
3284 KB |
Output is correct |
18 |
Correct |
16 ms |
3284 KB |
Output is correct |
19 |
Correct |
10 ms |
3284 KB |
Output is correct |
20 |
Correct |
8 ms |
3284 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
336 KB |
Output is correct |
29 |
Correct |
1 ms |
332 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Correct |
0 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
340 KB |
Output is correct |
33 |
Correct |
0 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
340 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
0 ms |
340 KB |
Output is correct |
37 |
Correct |
1 ms |
340 KB |
Output is correct |
38 |
Correct |
1 ms |
340 KB |
Output is correct |
39 |
Correct |
1 ms |
336 KB |
Output is correct |
40 |
Correct |
1 ms |
340 KB |
Output is correct |
41 |
Correct |
1 ms |
344 KB |
Output is correct |
42 |
Correct |
1 ms |
336 KB |
Output is correct |
43 |
Correct |
1 ms |
360 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 |
332 KB |
Output is correct |
47 |
Correct |
1 ms |
340 KB |
Output is correct |
48 |
Correct |
1 ms |
340 KB |
Output is correct |
49 |
Correct |
1 ms |
340 KB |
Output is correct |
50 |
Correct |
1 ms |
340 KB |
Output is correct |
51 |
Correct |
1 ms |
340 KB |
Output is correct |
52 |
Correct |
1 ms |
340 KB |
Output is correct |
53 |
Correct |
1 ms |
340 KB |
Output is correct |
54 |
Correct |
1 ms |
340 KB |
Output is correct |
55 |
Correct |
1 ms |
344 KB |
Output is correct |
56 |
Correct |
0 ms |
340 KB |
Output is correct |
57 |
Correct |
1 ms |
340 KB |
Output is correct |
58 |
Correct |
1 ms |
340 KB |
Output is correct |
59 |
Correct |
0 ms |
340 KB |
Output is correct |
60 |
Correct |
1 ms |
340 KB |
Output is correct |
61 |
Correct |
1 ms |
852 KB |
Output is correct |
62 |
Correct |
1 ms |
852 KB |
Output is correct |
63 |
Correct |
1 ms |
880 KB |
Output is correct |
64 |
Correct |
1 ms |
852 KB |
Output is correct |
65 |
Correct |
1 ms |
852 KB |
Output is correct |
66 |
Correct |
1 ms |
852 KB |
Output is correct |
67 |
Correct |
1 ms |
852 KB |
Output is correct |
68 |
Correct |
1 ms |
848 KB |
Output is correct |
69 |
Correct |
1 ms |
852 KB |
Output is correct |
70 |
Correct |
1 ms |
852 KB |
Output is correct |
71 |
Correct |
1 ms |
852 KB |
Output is correct |
72 |
Correct |
1 ms |
852 KB |
Output is correct |
73 |
Correct |
1 ms |
852 KB |
Output is correct |
74 |
Correct |
1 ms |
852 KB |
Output is correct |
75 |
Correct |
1 ms |
852 KB |
Output is correct |
76 |
Correct |
1 ms |
852 KB |
Output is correct |
77 |
Correct |
1 ms |
852 KB |
Output is correct |
78 |
Correct |
1 ms |
852 KB |
Output is correct |
79 |
Correct |
1 ms |
848 KB |
Output is correct |
80 |
Correct |
1 ms |
852 KB |
Output is correct |
81 |
Correct |
13 ms |
3296 KB |
Output is correct |
82 |
Correct |
16 ms |
3172 KB |
Output is correct |
83 |
Correct |
13 ms |
3284 KB |
Output is correct |
84 |
Correct |
14 ms |
3300 KB |
Output is correct |
85 |
Correct |
14 ms |
3300 KB |
Output is correct |
86 |
Correct |
11 ms |
3332 KB |
Output is correct |
87 |
Correct |
14 ms |
3284 KB |
Output is correct |
88 |
Correct |
6 ms |
3284 KB |
Output is correct |
89 |
Correct |
7 ms |
3296 KB |
Output is correct |
90 |
Correct |
7 ms |
3280 KB |
Output is correct |
91 |
Correct |
11 ms |
3280 KB |
Output is correct |
92 |
Correct |
8 ms |
3284 KB |
Output is correct |
93 |
Correct |
11 ms |
3284 KB |
Output is correct |
94 |
Correct |
13 ms |
3220 KB |
Output is correct |
95 |
Correct |
16 ms |
3304 KB |
Output is correct |
96 |
Correct |
13 ms |
3236 KB |
Output is correct |
97 |
Correct |
14 ms |
3304 KB |
Output is correct |
98 |
Correct |
8 ms |
3284 KB |
Output is correct |
99 |
Correct |
6 ms |
3284 KB |
Output is correct |
100 |
Correct |
10 ms |
3300 KB |
Output is correct |
101 |
Correct |
12 ms |
3284 KB |
Output is correct |
102 |
Correct |
12 ms |
3208 KB |
Output is correct |
103 |
Correct |
13 ms |
3284 KB |
Output is correct |
104 |
Correct |
11 ms |
3284 KB |
Output is correct |
105 |
Correct |
5 ms |
3284 KB |
Output is correct |