#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include <queue>
#include <cmath>
#include <random>
#include <chrono>
#include <iomanip>
#include <iostream>
using namespace std;
#define double long double
int log_ = 3;
int inf = 2000000000000000000;
int mod = 1102024631;
int p = 505;
bool cmp(pair <int, int> a, pair <int, int> b)
{
if (a.second < b.second)
{
return true;
}
return false;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n , k;
cin >> n >> k;
vector <pair <int, int>> vp(n);
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
vp[i] = { a, b };
}
sort(vp.begin(), vp.end(), cmp);
vector <vector <vector <double>>> dp0(n+1);
vector <vector <vector <double>>> dp1;
for (int i = 0; i <= n; i++)
{
dp0[i].resize(n + 1);
for (int j = 0; j <= n; j++)
{
dp0[i][j].resize(n + 1 , inf);
}
}
for (int i = 0; i <= n; i++)
{
dp0[0][0][i] = 0;
}
dp1 = dp0;
for (int k = 0; k < n; k++)
{
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
for (int col = 0; col <= n; col++)
{
if (i > 0)
{
if (vp[k].second != -1)
{
dp1[i][j][col] = min(dp1[i][j][col], dp0[i - 1][j][col] + ((0. + vp[k].second) / i));
}
}
if (j > 0)
{
dp1[i][j][col] = min(dp1[i][j][col], dp0[i][j - 1][col] + ((0. + vp[k].first) / (col+1)));
}
}
}
}
dp0 = dp1;
}
double ans = inf;
for (int i = 0; i <= n; i++)
{
for (int j = 0; j <= n; j++)
{
for (int col = 0; col <= n; col++)
{
if (col <= k)
{
if (i + j == k)
{
if (i == col)
{
ans = min(ans , dp0[i][j][col]);
}
}
}
}
}
}
cout << ans;
}
Compilation message
Main.cpp:21:11: warning: overflow in conversion from 'long int' to 'int' changes value from '2000000000000000000' to '1321730048' [-Woverflow]
21 | int inf = 2000000000000000000;
| ^~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
712 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
708 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
676 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
3 ms |
780 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
784 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
348 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
1 ms |
344 KB |
Output is correct |
8 |
Correct |
0 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
0 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Correct |
0 ms |
348 KB |
Output is correct |
13 |
Correct |
0 ms |
348 KB |
Output is correct |
14 |
Correct |
0 ms |
348 KB |
Output is correct |
15 |
Correct |
0 ms |
348 KB |
Output is correct |
16 |
Correct |
3 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
604 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
3 ms |
604 KB |
Output is correct |
20 |
Correct |
3 ms |
712 KB |
Output is correct |
21 |
Correct |
3 ms |
604 KB |
Output is correct |
22 |
Correct |
3 ms |
604 KB |
Output is correct |
23 |
Correct |
3 ms |
600 KB |
Output is correct |
24 |
Correct |
3 ms |
600 KB |
Output is correct |
25 |
Correct |
3 ms |
604 KB |
Output is correct |
26 |
Correct |
3 ms |
604 KB |
Output is correct |
27 |
Correct |
3 ms |
604 KB |
Output is correct |
28 |
Correct |
3 ms |
708 KB |
Output is correct |
29 |
Correct |
3 ms |
604 KB |
Output is correct |
30 |
Correct |
3 ms |
604 KB |
Output is correct |
31 |
Correct |
3 ms |
604 KB |
Output is correct |
32 |
Correct |
3 ms |
676 KB |
Output is correct |
33 |
Correct |
3 ms |
604 KB |
Output is correct |
34 |
Correct |
3 ms |
604 KB |
Output is correct |
35 |
Correct |
3 ms |
604 KB |
Output is correct |
36 |
Correct |
3 ms |
780 KB |
Output is correct |
37 |
Correct |
3 ms |
604 KB |
Output is correct |
38 |
Correct |
3 ms |
604 KB |
Output is correct |
39 |
Correct |
3 ms |
604 KB |
Output is correct |
40 |
Correct |
4 ms |
784 KB |
Output is correct |
41 |
Correct |
1641 ms |
33372 KB |
Output is correct |
42 |
Correct |
1456 ms |
33496 KB |
Output is correct |
43 |
Correct |
1554 ms |
33496 KB |
Output is correct |
44 |
Correct |
1444 ms |
33496 KB |
Output is correct |
45 |
Correct |
1573 ms |
33496 KB |
Output is correct |
46 |
Correct |
1468 ms |
33500 KB |
Output is correct |
47 |
Correct |
1551 ms |
33492 KB |
Output is correct |
48 |
Correct |
1392 ms |
33372 KB |
Output is correct |
49 |
Correct |
1538 ms |
33372 KB |
Output is correct |
50 |
Correct |
1396 ms |
33492 KB |
Output is correct |
51 |
Correct |
1530 ms |
33492 KB |
Output is correct |
52 |
Correct |
1401 ms |
33496 KB |
Output is correct |
53 |
Correct |
1561 ms |
33620 KB |
Output is correct |
54 |
Correct |
1531 ms |
33492 KB |
Output is correct |
55 |
Correct |
1540 ms |
33492 KB |
Output is correct |
56 |
Correct |
1578 ms |
33372 KB |
Output is correct |
57 |
Correct |
1534 ms |
33372 KB |
Output is correct |
58 |
Correct |
1570 ms |
33492 KB |
Output is correct |
59 |
Correct |
1566 ms |
33368 KB |
Output is correct |
60 |
Correct |
1535 ms |
33372 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
470 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Runtime error |
469 ms |
1048576 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |