//Challenge: Accepted
#include <bits/stdc++.h>
using namespace std;
#ifdef zisk
void debug(){cout << endl;}
template<class T, class ... U> void debug(T a, U ... b){cout << a << " ", debug(b...);}
template<class T> void pary(T l, T r) {
while (l != r) cout << *l << " ", l++;
cout << endl;
}
#else
#define debug(...) 0
#define pary(...) 0
#endif
#define ll long long
#define maxn 505
#define pii pair<int, int>
#define ff first
#define ss second
#define io ios_base::sync_with_stdio(0);cin.tie(0);
pii a[maxn];
const double inf = 1e9;
double dp[maxn][maxn];
ll mi[maxn][maxn];
int main() {
io
int n, k;
cin >> n >> k;
for (int i = 0;i < n;i++) {
cin >> a[i].ff >> a[i].ss;
if (a[i].ss == -1) a[i].ss = 1<<30;
}
sort(a, a + n, [&] (pii x, pii y){return (x.ss == y.ss ? x.ff > y.ff : x.ss < y.ss);});
for (int i = n - 1;i >= 0;i--) {
vector<pii> b;
for (int j = n-1;j >= i;j--) b.push_back(a[j]);
sort(b.begin(), b.end());
for (int j = 0;j < b.size();j++) mi[i][j+1] = mi[i][j] + b[j].ff;
}
double ans = 1e9;
ans = mi[0][k];
for (int i = 0;i <= k;i++) {
for (int x = 0;x <= k;x++) {
for (int y = 0;y <= k;y++) dp[x][y] = inf;
}
dp[0][0] = 0;
for (int x = 1;x <= k;x++) {
for (int y = 0;y <= k;y++) {
dp[x][y] = dp[x-1][y] + (double(a[x-1].ff)/(i+1));
if (y) {
dp[x][y] = min(dp[x][y], dp[x-1][y-1] + (double)a[x-1].ss/y);
}
}
ans = min(ans, dp[x][i] + (double(mi[x][k - x])) / (i+1));
}
}
cout << fixed << setprecision(10) << ans << "\n";
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:39:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
39 | for (int j = 0;j < b.size();j++) mi[i][j+1] = mi[i][j] + b[j].ff;
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
2380 KB |
Output is correct |
6 |
Correct |
9 ms |
2708 KB |
Output is correct |
7 |
Correct |
43 ms |
3288 KB |
Output is correct |
8 |
Correct |
110 ms |
3768 KB |
Output is correct |
9 |
Correct |
266 ms |
4260 KB |
Output is correct |
10 |
Correct |
97 ms |
3660 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
2380 KB |
Output is correct |
6 |
Correct |
9 ms |
2708 KB |
Output is correct |
7 |
Correct |
43 ms |
3288 KB |
Output is correct |
8 |
Correct |
110 ms |
3768 KB |
Output is correct |
9 |
Correct |
266 ms |
4260 KB |
Output is correct |
10 |
Correct |
97 ms |
3660 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
2900 KB |
Output is correct |
13 |
Correct |
12 ms |
2808 KB |
Output is correct |
14 |
Correct |
11 ms |
2892 KB |
Output is correct |
15 |
Correct |
91 ms |
3672 KB |
Output is correct |
16 |
Correct |
110 ms |
3660 KB |
Output is correct |
17 |
Correct |
100 ms |
3668 KB |
Output is correct |
18 |
Correct |
262 ms |
4264 KB |
Output is correct |
19 |
Correct |
260 ms |
4300 KB |
Output is correct |
20 |
Correct |
270 ms |
4268 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 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 |
384 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 |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 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 |
384 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
332 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 |
460 KB |
Output is correct |
25 |
Correct |
0 ms |
460 KB |
Output is correct |
26 |
Correct |
0 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
404 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 |
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 |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 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 |
0 ms |
332 KB |
Output is correct |
6 |
Correct |
0 ms |
332 KB |
Output is correct |
7 |
Correct |
1 ms |
332 KB |
Output is correct |
8 |
Correct |
0 ms |
332 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 |
384 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 |
332 KB |
Output is correct |
17 |
Correct |
1 ms |
332 KB |
Output is correct |
18 |
Correct |
0 ms |
332 KB |
Output is correct |
19 |
Correct |
1 ms |
460 KB |
Output is correct |
20 |
Correct |
1 ms |
332 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 |
460 KB |
Output is correct |
25 |
Correct |
0 ms |
460 KB |
Output is correct |
26 |
Correct |
0 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
1 ms |
332 KB |
Output is correct |
29 |
Correct |
0 ms |
332 KB |
Output is correct |
30 |
Correct |
0 ms |
332 KB |
Output is correct |
31 |
Correct |
1 ms |
332 KB |
Output is correct |
32 |
Correct |
1 ms |
404 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 |
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 |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
332 KB |
Output is correct |
40 |
Correct |
0 ms |
332 KB |
Output is correct |
41 |
Correct |
1 ms |
716 KB |
Output is correct |
42 |
Correct |
1 ms |
716 KB |
Output is correct |
43 |
Correct |
1 ms |
844 KB |
Output is correct |
44 |
Correct |
1 ms |
716 KB |
Output is correct |
45 |
Correct |
1 ms |
844 KB |
Output is correct |
46 |
Correct |
1 ms |
844 KB |
Output is correct |
47 |
Correct |
2 ms |
972 KB |
Output is correct |
48 |
Correct |
1 ms |
972 KB |
Output is correct |
49 |
Correct |
3 ms |
972 KB |
Output is correct |
50 |
Correct |
2 ms |
972 KB |
Output is correct |
51 |
Correct |
4 ms |
1100 KB |
Output is correct |
52 |
Correct |
4 ms |
1152 KB |
Output is correct |
53 |
Correct |
2 ms |
972 KB |
Output is correct |
54 |
Correct |
2 ms |
972 KB |
Output is correct |
55 |
Correct |
3 ms |
972 KB |
Output is correct |
56 |
Correct |
2 ms |
972 KB |
Output is correct |
57 |
Correct |
2 ms |
972 KB |
Output is correct |
58 |
Correct |
2 ms |
972 KB |
Output is correct |
59 |
Correct |
1 ms |
972 KB |
Output is correct |
60 |
Correct |
1 ms |
972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
269 ms |
4268 KB |
Output is correct |
2 |
Correct |
305 ms |
4264 KB |
Output is correct |
3 |
Correct |
266 ms |
4268 KB |
Output is correct |
4 |
Correct |
263 ms |
4268 KB |
Output is correct |
5 |
Correct |
283 ms |
4264 KB |
Output is correct |
6 |
Correct |
290 ms |
4268 KB |
Output is correct |
7 |
Correct |
259 ms |
4280 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
332 KB |
Output is correct |
2 |
Correct |
0 ms |
332 KB |
Output is correct |
3 |
Correct |
1 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Correct |
5 ms |
2380 KB |
Output is correct |
6 |
Correct |
9 ms |
2708 KB |
Output is correct |
7 |
Correct |
43 ms |
3288 KB |
Output is correct |
8 |
Correct |
110 ms |
3768 KB |
Output is correct |
9 |
Correct |
266 ms |
4260 KB |
Output is correct |
10 |
Correct |
97 ms |
3660 KB |
Output is correct |
11 |
Correct |
0 ms |
332 KB |
Output is correct |
12 |
Correct |
11 ms |
2900 KB |
Output is correct |
13 |
Correct |
12 ms |
2808 KB |
Output is correct |
14 |
Correct |
11 ms |
2892 KB |
Output is correct |
15 |
Correct |
91 ms |
3672 KB |
Output is correct |
16 |
Correct |
110 ms |
3660 KB |
Output is correct |
17 |
Correct |
100 ms |
3668 KB |
Output is correct |
18 |
Correct |
262 ms |
4264 KB |
Output is correct |
19 |
Correct |
260 ms |
4300 KB |
Output is correct |
20 |
Correct |
270 ms |
4268 KB |
Output is correct |
21 |
Correct |
0 ms |
332 KB |
Output is correct |
22 |
Correct |
1 ms |
332 KB |
Output is correct |
23 |
Correct |
0 ms |
332 KB |
Output is correct |
24 |
Correct |
1 ms |
332 KB |
Output is correct |
25 |
Correct |
0 ms |
332 KB |
Output is correct |
26 |
Correct |
0 ms |
332 KB |
Output is correct |
27 |
Correct |
1 ms |
332 KB |
Output is correct |
28 |
Correct |
0 ms |
332 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 |
384 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 |
332 KB |
Output is correct |
37 |
Correct |
1 ms |
332 KB |
Output is correct |
38 |
Correct |
0 ms |
332 KB |
Output is correct |
39 |
Correct |
1 ms |
460 KB |
Output is correct |
40 |
Correct |
1 ms |
332 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 |
460 KB |
Output is correct |
45 |
Correct |
0 ms |
460 KB |
Output is correct |
46 |
Correct |
0 ms |
460 KB |
Output is correct |
47 |
Correct |
1 ms |
332 KB |
Output is correct |
48 |
Correct |
1 ms |
332 KB |
Output is correct |
49 |
Correct |
0 ms |
332 KB |
Output is correct |
50 |
Correct |
0 ms |
332 KB |
Output is correct |
51 |
Correct |
1 ms |
332 KB |
Output is correct |
52 |
Correct |
1 ms |
404 KB |
Output is correct |
53 |
Correct |
1 ms |
332 KB |
Output is correct |
54 |
Correct |
1 ms |
332 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 |
332 KB |
Output is correct |
59 |
Correct |
1 ms |
332 KB |
Output is correct |
60 |
Correct |
0 ms |
332 KB |
Output is correct |
61 |
Correct |
1 ms |
716 KB |
Output is correct |
62 |
Correct |
1 ms |
716 KB |
Output is correct |
63 |
Correct |
1 ms |
844 KB |
Output is correct |
64 |
Correct |
1 ms |
716 KB |
Output is correct |
65 |
Correct |
1 ms |
844 KB |
Output is correct |
66 |
Correct |
1 ms |
844 KB |
Output is correct |
67 |
Correct |
2 ms |
972 KB |
Output is correct |
68 |
Correct |
1 ms |
972 KB |
Output is correct |
69 |
Correct |
3 ms |
972 KB |
Output is correct |
70 |
Correct |
2 ms |
972 KB |
Output is correct |
71 |
Correct |
4 ms |
1100 KB |
Output is correct |
72 |
Correct |
4 ms |
1152 KB |
Output is correct |
73 |
Correct |
2 ms |
972 KB |
Output is correct |
74 |
Correct |
2 ms |
972 KB |
Output is correct |
75 |
Correct |
3 ms |
972 KB |
Output is correct |
76 |
Correct |
2 ms |
972 KB |
Output is correct |
77 |
Correct |
2 ms |
972 KB |
Output is correct |
78 |
Correct |
2 ms |
972 KB |
Output is correct |
79 |
Correct |
1 ms |
972 KB |
Output is correct |
80 |
Correct |
1 ms |
972 KB |
Output is correct |
81 |
Correct |
269 ms |
4268 KB |
Output is correct |
82 |
Correct |
305 ms |
4264 KB |
Output is correct |
83 |
Correct |
266 ms |
4268 KB |
Output is correct |
84 |
Correct |
263 ms |
4268 KB |
Output is correct |
85 |
Correct |
283 ms |
4264 KB |
Output is correct |
86 |
Correct |
290 ms |
4268 KB |
Output is correct |
87 |
Correct |
259 ms |
4280 KB |
Output is correct |
88 |
Correct |
11 ms |
2444 KB |
Output is correct |
89 |
Correct |
8 ms |
2504 KB |
Output is correct |
90 |
Correct |
12 ms |
2696 KB |
Output is correct |
91 |
Correct |
13 ms |
2764 KB |
Output is correct |
92 |
Correct |
40 ms |
3212 KB |
Output is correct |
93 |
Correct |
47 ms |
3280 KB |
Output is correct |
94 |
Correct |
115 ms |
3736 KB |
Output is correct |
95 |
Correct |
125 ms |
3660 KB |
Output is correct |
96 |
Correct |
196 ms |
4068 KB |
Output is correct |
97 |
Correct |
202 ms |
4044 KB |
Output is correct |
98 |
Correct |
97 ms |
3660 KB |
Output is correct |
99 |
Correct |
96 ms |
3672 KB |
Output is correct |
100 |
Correct |
98 ms |
3668 KB |
Output is correct |
101 |
Correct |
99 ms |
3660 KB |
Output is correct |
102 |
Correct |
98 ms |
3668 KB |
Output is correct |
103 |
Correct |
98 ms |
3668 KB |
Output is correct |
104 |
Correct |
96 ms |
3660 KB |
Output is correct |
105 |
Correct |
92 ms |
3668 KB |
Output is correct |