#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 i = 1 ; i <= n ; i++) {//first i people
//cout << i << ": \n";
for (int j = 0 ; j <= i ; j++) {// have how many people
//cout << j << ": ";
for (int k = 1 ; k <= j+1 ; 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] / k));
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) 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 |
415 ms |
1018748 KB |
Output is correct |
2 |
Correct |
359 ms |
1018520 KB |
Output is correct |
3 |
Correct |
367 ms |
1018448 KB |
Output is correct |
4 |
Correct |
358 ms |
1018508 KB |
Output is correct |
5 |
Correct |
417 ms |
1018516 KB |
Output is correct |
6 |
Correct |
415 ms |
1018584 KB |
Output is correct |
7 |
Correct |
426 ms |
1018788 KB |
Output is correct |
8 |
Correct |
427 ms |
1018580 KB |
Output is correct |
9 |
Correct |
416 ms |
1018384 KB |
Output is correct |
10 |
Correct |
430 ms |
1018448 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
415 ms |
1018748 KB |
Output is correct |
2 |
Correct |
359 ms |
1018520 KB |
Output is correct |
3 |
Correct |
367 ms |
1018448 KB |
Output is correct |
4 |
Correct |
358 ms |
1018508 KB |
Output is correct |
5 |
Correct |
417 ms |
1018516 KB |
Output is correct |
6 |
Correct |
415 ms |
1018584 KB |
Output is correct |
7 |
Correct |
426 ms |
1018788 KB |
Output is correct |
8 |
Correct |
427 ms |
1018580 KB |
Output is correct |
9 |
Correct |
416 ms |
1018384 KB |
Output is correct |
10 |
Correct |
430 ms |
1018448 KB |
Output is correct |
11 |
Correct |
353 ms |
1018588 KB |
Output is correct |
12 |
Correct |
441 ms |
1018588 KB |
Output is correct |
13 |
Correct |
421 ms |
1018452 KB |
Output is correct |
14 |
Correct |
421 ms |
1018964 KB |
Output is correct |
15 |
Correct |
452 ms |
1018448 KB |
Output is correct |
16 |
Correct |
425 ms |
1018764 KB |
Output is correct |
17 |
Correct |
412 ms |
1018520 KB |
Output is correct |
18 |
Correct |
442 ms |
1018584 KB |
Output is correct |
19 |
Correct |
435 ms |
1018584 KB |
Output is correct |
20 |
Correct |
414 ms |
1018700 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
1018700 KB |
Output is correct |
2 |
Correct |
372 ms |
1018340 KB |
Output is correct |
3 |
Correct |
355 ms |
1018724 KB |
Output is correct |
4 |
Correct |
363 ms |
1018384 KB |
Output is correct |
5 |
Correct |
365 ms |
1018448 KB |
Output is correct |
6 |
Correct |
358 ms |
1018448 KB |
Output is correct |
7 |
Correct |
361 ms |
1018508 KB |
Output is correct |
8 |
Correct |
359 ms |
1018448 KB |
Output is correct |
9 |
Incorrect |
366 ms |
1018504 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
1018700 KB |
Output is correct |
2 |
Correct |
372 ms |
1018340 KB |
Output is correct |
3 |
Correct |
355 ms |
1018724 KB |
Output is correct |
4 |
Correct |
363 ms |
1018384 KB |
Output is correct |
5 |
Correct |
365 ms |
1018448 KB |
Output is correct |
6 |
Correct |
358 ms |
1018448 KB |
Output is correct |
7 |
Correct |
361 ms |
1018508 KB |
Output is correct |
8 |
Correct |
359 ms |
1018448 KB |
Output is correct |
9 |
Incorrect |
366 ms |
1018504 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
368 ms |
1018700 KB |
Output is correct |
2 |
Correct |
372 ms |
1018340 KB |
Output is correct |
3 |
Correct |
355 ms |
1018724 KB |
Output is correct |
4 |
Correct |
363 ms |
1018384 KB |
Output is correct |
5 |
Correct |
365 ms |
1018448 KB |
Output is correct |
6 |
Correct |
358 ms |
1018448 KB |
Output is correct |
7 |
Correct |
361 ms |
1018508 KB |
Output is correct |
8 |
Correct |
359 ms |
1018448 KB |
Output is correct |
9 |
Incorrect |
366 ms |
1018504 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
444 ms |
1018460 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
415 ms |
1018748 KB |
Output is correct |
2 |
Correct |
359 ms |
1018520 KB |
Output is correct |
3 |
Correct |
367 ms |
1018448 KB |
Output is correct |
4 |
Correct |
358 ms |
1018508 KB |
Output is correct |
5 |
Correct |
417 ms |
1018516 KB |
Output is correct |
6 |
Correct |
415 ms |
1018584 KB |
Output is correct |
7 |
Correct |
426 ms |
1018788 KB |
Output is correct |
8 |
Correct |
427 ms |
1018580 KB |
Output is correct |
9 |
Correct |
416 ms |
1018384 KB |
Output is correct |
10 |
Correct |
430 ms |
1018448 KB |
Output is correct |
11 |
Correct |
353 ms |
1018588 KB |
Output is correct |
12 |
Correct |
441 ms |
1018588 KB |
Output is correct |
13 |
Correct |
421 ms |
1018452 KB |
Output is correct |
14 |
Correct |
421 ms |
1018964 KB |
Output is correct |
15 |
Correct |
452 ms |
1018448 KB |
Output is correct |
16 |
Correct |
425 ms |
1018764 KB |
Output is correct |
17 |
Correct |
412 ms |
1018520 KB |
Output is correct |
18 |
Correct |
442 ms |
1018584 KB |
Output is correct |
19 |
Correct |
435 ms |
1018584 KB |
Output is correct |
20 |
Correct |
414 ms |
1018700 KB |
Output is correct |
21 |
Correct |
368 ms |
1018700 KB |
Output is correct |
22 |
Correct |
372 ms |
1018340 KB |
Output is correct |
23 |
Correct |
355 ms |
1018724 KB |
Output is correct |
24 |
Correct |
363 ms |
1018384 KB |
Output is correct |
25 |
Correct |
365 ms |
1018448 KB |
Output is correct |
26 |
Correct |
358 ms |
1018448 KB |
Output is correct |
27 |
Correct |
361 ms |
1018508 KB |
Output is correct |
28 |
Correct |
359 ms |
1018448 KB |
Output is correct |
29 |
Incorrect |
366 ms |
1018504 KB |
Output isn't correct |
30 |
Halted |
0 ms |
0 KB |
- |