#include<bits/stdc++.h>
#define pii pair<int, int>
#define INF 5000000
using namespace std;
bool cmp(pii a, pii b) {
if (a.second == -1 && b.second == -1) return a.first < b.first;
if (a.second == -1) return (1 > 2);
if (b.second == -1) return (1 < 2);
if (a.second == b.second) return a.first > b.first;
return a.second < b.second;
}
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, K;
cin >> n >> K;
vector<pii>v(n+1);
vector<double>a(n+1), b(n+1);
for (int i = 1 ; i <= n ;i++) cin >> v[i].first >> v[i].second;
sort(v.begin()+1, v.end(), cmp);
for (int i = 1 ; i <= n ;i++) a[i] = (double)v[i].first, b[i] = (double)v[i].second;
vector<vector<vector<double> > >dp(505, vector<vector<double> >(505, vector<double>(505, INF)) );
//double dp[505][505][505];
dp[0][0][1] = 0.0;
double ans = INF;
for (int help = 1 ; help <= K ; help++) {
for (int i = 1 ; i <= n ; i++) {//first i people
//cout << i << ": \n";
for (int j = 0 ; j <= min(K, i) ; j++) {// have how many people
//cout << j << ": ";
for (int k = 1 ; k <= min(j+1, help) ; k++) {// get how many people
dp[i][j][k] = dp[i-1][j][k];
if (j > 0) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-1][k] + (a[i] / help));
if (k > 1 && b[i] != -1) dp[i][j][k] = min(dp[i][j][k], dp[i-1][j-1][k-1] + b[i] / (k-1));
//cout << dp[i][j][k] <<" ";
if (j == K && k == help) ans = min(ans, dp[i][j][k]);
}
//cout << "\n";
}
}
}
cout << fixed << setprecision(6) << ans << "\n";
//for (auto &i : v) cout << i.first <<" " << i.second << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
1018320 KB |
Output is correct |
2 |
Correct |
408 ms |
1018604 KB |
Output is correct |
3 |
Correct |
401 ms |
1018452 KB |
Output is correct |
4 |
Correct |
420 ms |
1018584 KB |
Output is correct |
5 |
Correct |
498 ms |
1018580 KB |
Output is correct |
6 |
Correct |
1674 ms |
1018584 KB |
Output is correct |
7 |
Execution timed out |
2614 ms |
1018668 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
1018320 KB |
Output is correct |
2 |
Correct |
408 ms |
1018604 KB |
Output is correct |
3 |
Correct |
401 ms |
1018452 KB |
Output is correct |
4 |
Correct |
420 ms |
1018584 KB |
Output is correct |
5 |
Correct |
498 ms |
1018580 KB |
Output is correct |
6 |
Correct |
1674 ms |
1018584 KB |
Output is correct |
7 |
Execution timed out |
2614 ms |
1018668 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
1018684 KB |
Output is correct |
2 |
Correct |
402 ms |
1018452 KB |
Output is correct |
3 |
Correct |
411 ms |
1018620 KB |
Output is correct |
4 |
Correct |
402 ms |
1018508 KB |
Output is correct |
5 |
Correct |
408 ms |
1018820 KB |
Output is correct |
6 |
Correct |
406 ms |
1018484 KB |
Output is correct |
7 |
Correct |
404 ms |
1018416 KB |
Output is correct |
8 |
Correct |
409 ms |
1018452 KB |
Output is correct |
9 |
Correct |
402 ms |
1018568 KB |
Output is correct |
10 |
Correct |
406 ms |
1018412 KB |
Output is correct |
11 |
Correct |
406 ms |
1018452 KB |
Output is correct |
12 |
Correct |
406 ms |
1018452 KB |
Output is correct |
13 |
Correct |
402 ms |
1018448 KB |
Output is correct |
14 |
Correct |
407 ms |
1018360 KB |
Output is correct |
15 |
Correct |
402 ms |
1018452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
1018684 KB |
Output is correct |
2 |
Correct |
402 ms |
1018452 KB |
Output is correct |
3 |
Correct |
411 ms |
1018620 KB |
Output is correct |
4 |
Correct |
402 ms |
1018508 KB |
Output is correct |
5 |
Correct |
408 ms |
1018820 KB |
Output is correct |
6 |
Correct |
406 ms |
1018484 KB |
Output is correct |
7 |
Correct |
404 ms |
1018416 KB |
Output is correct |
8 |
Correct |
409 ms |
1018452 KB |
Output is correct |
9 |
Correct |
402 ms |
1018568 KB |
Output is correct |
10 |
Correct |
406 ms |
1018412 KB |
Output is correct |
11 |
Correct |
406 ms |
1018452 KB |
Output is correct |
12 |
Correct |
406 ms |
1018452 KB |
Output is correct |
13 |
Correct |
402 ms |
1018448 KB |
Output is correct |
14 |
Correct |
407 ms |
1018360 KB |
Output is correct |
15 |
Correct |
402 ms |
1018452 KB |
Output is correct |
16 |
Correct |
401 ms |
1018448 KB |
Output is correct |
17 |
Correct |
403 ms |
1018576 KB |
Output is correct |
18 |
Correct |
405 ms |
1018476 KB |
Output is correct |
19 |
Correct |
404 ms |
1018468 KB |
Output is correct |
20 |
Correct |
400 ms |
1018448 KB |
Output is correct |
21 |
Correct |
409 ms |
1018588 KB |
Output is correct |
22 |
Correct |
406 ms |
1018440 KB |
Output is correct |
23 |
Correct |
403 ms |
1018444 KB |
Output is correct |
24 |
Correct |
414 ms |
1018424 KB |
Output is correct |
25 |
Correct |
403 ms |
1018452 KB |
Output is correct |
26 |
Correct |
402 ms |
1018556 KB |
Output is correct |
27 |
Correct |
409 ms |
1018452 KB |
Output is correct |
28 |
Correct |
425 ms |
1018708 KB |
Output is correct |
29 |
Correct |
407 ms |
1018452 KB |
Output is correct |
30 |
Correct |
409 ms |
1018452 KB |
Output is correct |
31 |
Correct |
409 ms |
1018448 KB |
Output is correct |
32 |
Correct |
403 ms |
1018368 KB |
Output is correct |
33 |
Correct |
416 ms |
1018704 KB |
Output is correct |
34 |
Correct |
425 ms |
1018376 KB |
Output is correct |
35 |
Correct |
413 ms |
1018460 KB |
Output is correct |
36 |
Correct |
424 ms |
1018348 KB |
Output is correct |
37 |
Correct |
399 ms |
1018568 KB |
Output is correct |
38 |
Correct |
405 ms |
1018448 KB |
Output is correct |
39 |
Correct |
407 ms |
1018536 KB |
Output is correct |
40 |
Correct |
404 ms |
1018452 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
414 ms |
1018684 KB |
Output is correct |
2 |
Correct |
402 ms |
1018452 KB |
Output is correct |
3 |
Correct |
411 ms |
1018620 KB |
Output is correct |
4 |
Correct |
402 ms |
1018508 KB |
Output is correct |
5 |
Correct |
408 ms |
1018820 KB |
Output is correct |
6 |
Correct |
406 ms |
1018484 KB |
Output is correct |
7 |
Correct |
404 ms |
1018416 KB |
Output is correct |
8 |
Correct |
409 ms |
1018452 KB |
Output is correct |
9 |
Correct |
402 ms |
1018568 KB |
Output is correct |
10 |
Correct |
406 ms |
1018412 KB |
Output is correct |
11 |
Correct |
406 ms |
1018452 KB |
Output is correct |
12 |
Correct |
406 ms |
1018452 KB |
Output is correct |
13 |
Correct |
402 ms |
1018448 KB |
Output is correct |
14 |
Correct |
407 ms |
1018360 KB |
Output is correct |
15 |
Correct |
402 ms |
1018452 KB |
Output is correct |
16 |
Correct |
401 ms |
1018448 KB |
Output is correct |
17 |
Correct |
403 ms |
1018576 KB |
Output is correct |
18 |
Correct |
405 ms |
1018476 KB |
Output is correct |
19 |
Correct |
404 ms |
1018468 KB |
Output is correct |
20 |
Correct |
400 ms |
1018448 KB |
Output is correct |
21 |
Correct |
409 ms |
1018588 KB |
Output is correct |
22 |
Correct |
406 ms |
1018440 KB |
Output is correct |
23 |
Correct |
403 ms |
1018444 KB |
Output is correct |
24 |
Correct |
414 ms |
1018424 KB |
Output is correct |
25 |
Correct |
403 ms |
1018452 KB |
Output is correct |
26 |
Correct |
402 ms |
1018556 KB |
Output is correct |
27 |
Correct |
409 ms |
1018452 KB |
Output is correct |
28 |
Correct |
425 ms |
1018708 KB |
Output is correct |
29 |
Correct |
407 ms |
1018452 KB |
Output is correct |
30 |
Correct |
409 ms |
1018452 KB |
Output is correct |
31 |
Correct |
409 ms |
1018448 KB |
Output is correct |
32 |
Correct |
403 ms |
1018368 KB |
Output is correct |
33 |
Correct |
416 ms |
1018704 KB |
Output is correct |
34 |
Correct |
425 ms |
1018376 KB |
Output is correct |
35 |
Correct |
413 ms |
1018460 KB |
Output is correct |
36 |
Correct |
424 ms |
1018348 KB |
Output is correct |
37 |
Correct |
399 ms |
1018568 KB |
Output is correct |
38 |
Correct |
405 ms |
1018448 KB |
Output is correct |
39 |
Correct |
407 ms |
1018536 KB |
Output is correct |
40 |
Correct |
404 ms |
1018452 KB |
Output is correct |
41 |
Correct |
413 ms |
1018448 KB |
Output is correct |
42 |
Correct |
407 ms |
1018592 KB |
Output is correct |
43 |
Correct |
410 ms |
1018452 KB |
Output is correct |
44 |
Correct |
411 ms |
1018564 KB |
Output is correct |
45 |
Correct |
413 ms |
1018452 KB |
Output is correct |
46 |
Correct |
417 ms |
1018408 KB |
Output is correct |
47 |
Correct |
419 ms |
1018432 KB |
Output is correct |
48 |
Correct |
417 ms |
1018544 KB |
Output is correct |
49 |
Correct |
438 ms |
1018708 KB |
Output is correct |
50 |
Correct |
433 ms |
1018452 KB |
Output is correct |
51 |
Correct |
444 ms |
1018452 KB |
Output is correct |
52 |
Correct |
444 ms |
1018572 KB |
Output is correct |
53 |
Correct |
427 ms |
1018392 KB |
Output is correct |
54 |
Correct |
424 ms |
1018464 KB |
Output is correct |
55 |
Correct |
415 ms |
1018448 KB |
Output is correct |
56 |
Correct |
419 ms |
1018392 KB |
Output is correct |
57 |
Correct |
422 ms |
1018464 KB |
Output is correct |
58 |
Correct |
430 ms |
1018528 KB |
Output is correct |
59 |
Correct |
431 ms |
1018452 KB |
Output is correct |
60 |
Correct |
427 ms |
1018684 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2611 ms |
1018516 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
446 ms |
1018320 KB |
Output is correct |
2 |
Correct |
408 ms |
1018604 KB |
Output is correct |
3 |
Correct |
401 ms |
1018452 KB |
Output is correct |
4 |
Correct |
420 ms |
1018584 KB |
Output is correct |
5 |
Correct |
498 ms |
1018580 KB |
Output is correct |
6 |
Correct |
1674 ms |
1018584 KB |
Output is correct |
7 |
Execution timed out |
2614 ms |
1018668 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |