#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define prn printf
#define scn scanf
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
const int nax = 500;
const int inf = 1e9;
int n,k;
double memo[nax+5][nax+5][nax+5];
vector<pii> a;
// double dp(int idx, int col, int rem) {
// if(rem == 0) return 0;
// if(idx == n) return inf;
// double &ret = memo[idx][col][rem];
// if(ret!=0) return ret;
// ret = dp(idx+1, col, rem); // ga ambil
// if(a[idx].fi != inf) ret = min(ret, (double)a[idx].fi/col + dp(idx+1, col+1, rem-1));
// else ret = min(ret, (double)a[idx].se/col + dp(idx+1,col,rem-1));
// // cerr << idx << " " << col << " " << rem << " = " << ret << endl;
// return ret;
// }
double dp (int idx, int col, int vote, int tcol) {
if(col + vote == 0) return 0;
if(idx==n) return inf;
double &ret = memo[idx][col][vote];
if(ret!=0) return ret;
ret = dp(idx+1, col, vote, tcol);
if(col>0 && a[idx].fi != inf) ret = min(ret, (double)a[idx].fi/(tcol-col+1) + dp(idx+1, col-1, vote, tcol)); //consider jd collaborator
if(vote>0) ret = min(ret, (double)a[idx].se/(tcol+1) + dp(idx+1,col,vote-1, tcol));
//cerr << idx << " " << col << " " << vote << endl;
return ret;
}
signed main () {
scn("%d%d", &n, &k);
a.assign(n,{0,0});
for(int i=0; i<n; i++) {
scn("%d%d", &a[i].se, &a[i].fi);
if(a[i].fi == -1) a[i].fi = inf;
}
sort(a.begin(), a.end());
//for(int i=0; i<n; i++) //cerr << a[i].fi << " " << a[i].se << endl;
double ans = inf;
for(int c = 0; c <= min(n,k); c++) {
//cerr << " :: " << c << endl;
for(int i=0;i<n;i++) for(int j=0;j<n; j++) for(int k=0; k<n; k++) memo[i][j][k] = 0;
ans = min(ans, dp(0, c, k-c, c));
}
prn("%f", ans);
}
/*
dp(i,j,k) = time minimum untuk visit k kota up to index i
ddn j collaboratior
dp(i,j,0) = 0
ambil b
dp(i+1, j+1, k-1) + b[i]
ambil a
dp(i+1, j, k-1) + a[i]
ga ambil
dp(i+1, j+1, k)
*/
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:50:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
50 | scn("%d%d", &n, &k);
| ^
Main.cpp:54:12: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
54 | scn("%d%d", &a[i].se, &a[i].fi);
| ^
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Execution timed out |
2601 ms |
990540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Execution timed out |
2601 ms |
990540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
1868 KB |
Output is correct |
17 |
Correct |
1 ms |
1868 KB |
Output is correct |
18 |
Correct |
1 ms |
1868 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
1 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1868 KB |
Output is correct |
22 |
Correct |
1 ms |
1868 KB |
Output is correct |
23 |
Correct |
1 ms |
1868 KB |
Output is correct |
24 |
Correct |
1 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1996 KB |
Output is correct |
26 |
Correct |
2 ms |
1996 KB |
Output is correct |
27 |
Correct |
1 ms |
1868 KB |
Output is correct |
28 |
Correct |
1 ms |
1868 KB |
Output is correct |
29 |
Correct |
1 ms |
1868 KB |
Output is correct |
30 |
Correct |
1 ms |
1868 KB |
Output is correct |
31 |
Correct |
1 ms |
1868 KB |
Output is correct |
32 |
Correct |
1 ms |
1868 KB |
Output is correct |
33 |
Correct |
1 ms |
1868 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
1 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
1868 KB |
Output is correct |
37 |
Correct |
1 ms |
1868 KB |
Output is correct |
38 |
Correct |
1 ms |
1868 KB |
Output is correct |
39 |
Correct |
1 ms |
1868 KB |
Output is correct |
40 |
Correct |
1 ms |
1868 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
460 KB |
Output is correct |
2 |
Correct |
0 ms |
460 KB |
Output is correct |
3 |
Correct |
1 ms |
460 KB |
Output is correct |
4 |
Correct |
0 ms |
460 KB |
Output is correct |
5 |
Correct |
1 ms |
460 KB |
Output is correct |
6 |
Correct |
1 ms |
460 KB |
Output is correct |
7 |
Correct |
1 ms |
460 KB |
Output is correct |
8 |
Correct |
1 ms |
472 KB |
Output is correct |
9 |
Correct |
0 ms |
460 KB |
Output is correct |
10 |
Correct |
0 ms |
460 KB |
Output is correct |
11 |
Correct |
1 ms |
460 KB |
Output is correct |
12 |
Correct |
1 ms |
460 KB |
Output is correct |
13 |
Correct |
0 ms |
460 KB |
Output is correct |
14 |
Correct |
0 ms |
332 KB |
Output is correct |
15 |
Correct |
0 ms |
460 KB |
Output is correct |
16 |
Correct |
1 ms |
1868 KB |
Output is correct |
17 |
Correct |
1 ms |
1868 KB |
Output is correct |
18 |
Correct |
1 ms |
1868 KB |
Output is correct |
19 |
Correct |
1 ms |
1868 KB |
Output is correct |
20 |
Correct |
1 ms |
1868 KB |
Output is correct |
21 |
Correct |
1 ms |
1868 KB |
Output is correct |
22 |
Correct |
1 ms |
1868 KB |
Output is correct |
23 |
Correct |
1 ms |
1868 KB |
Output is correct |
24 |
Correct |
1 ms |
1868 KB |
Output is correct |
25 |
Correct |
1 ms |
1996 KB |
Output is correct |
26 |
Correct |
2 ms |
1996 KB |
Output is correct |
27 |
Correct |
1 ms |
1868 KB |
Output is correct |
28 |
Correct |
1 ms |
1868 KB |
Output is correct |
29 |
Correct |
1 ms |
1868 KB |
Output is correct |
30 |
Correct |
1 ms |
1868 KB |
Output is correct |
31 |
Correct |
1 ms |
1868 KB |
Output is correct |
32 |
Correct |
1 ms |
1868 KB |
Output is correct |
33 |
Correct |
1 ms |
1868 KB |
Output is correct |
34 |
Correct |
2 ms |
1868 KB |
Output is correct |
35 |
Correct |
1 ms |
1868 KB |
Output is correct |
36 |
Correct |
1 ms |
1868 KB |
Output is correct |
37 |
Correct |
1 ms |
1868 KB |
Output is correct |
38 |
Correct |
1 ms |
1868 KB |
Output is correct |
39 |
Correct |
1 ms |
1868 KB |
Output is correct |
40 |
Correct |
1 ms |
1868 KB |
Output is correct |
41 |
Correct |
45 ms |
40136 KB |
Output is correct |
42 |
Correct |
42 ms |
40140 KB |
Output is correct |
43 |
Correct |
75 ms |
40208 KB |
Output is correct |
44 |
Correct |
75 ms |
40104 KB |
Output is correct |
45 |
Correct |
135 ms |
40276 KB |
Output is correct |
46 |
Correct |
132 ms |
40140 KB |
Output is correct |
47 |
Correct |
196 ms |
40208 KB |
Output is correct |
48 |
Correct |
206 ms |
40208 KB |
Output is correct |
49 |
Correct |
296 ms |
40208 KB |
Output is correct |
50 |
Correct |
297 ms |
40216 KB |
Output is correct |
51 |
Correct |
443 ms |
40472 KB |
Output is correct |
52 |
Correct |
435 ms |
40468 KB |
Output is correct |
53 |
Correct |
215 ms |
40204 KB |
Output is correct |
54 |
Correct |
204 ms |
40140 KB |
Output is correct |
55 |
Correct |
206 ms |
40140 KB |
Output is correct |
56 |
Correct |
199 ms |
40140 KB |
Output is correct |
57 |
Correct |
218 ms |
40208 KB |
Output is correct |
58 |
Correct |
200 ms |
40204 KB |
Output is correct |
59 |
Correct |
204 ms |
40224 KB |
Output is correct |
60 |
Correct |
199 ms |
40204 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Execution timed out |
2633 ms |
990644 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
1 ms |
204 KB |
Output is correct |
3 |
Correct |
0 ms |
332 KB |
Output is correct |
4 |
Correct |
0 ms |
332 KB |
Output is correct |
5 |
Execution timed out |
2601 ms |
990540 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |