#include <bits/stdc++.h>
using namespace std;
using ld = long double;
#define int long long
int n,k;
ld m;
ld a[505],b[505];
ld v[505];
int better(int x,int y,ld t)
{
ld p1 = v[y] + b[x] / t,p2 = v[x] + b[y] / t;
//cout << x << ' ' << y << ' ' << t << ' ' << p1 << ' ' << p2 << endl;
if (p1 < p2)
return x;
//cout << y << endl;
return y;
}
ld solve(int pos,vector<int>ids)
{
if (pos == m + 1)
{
vector<ld>as;
for (auto it : ids)
as.push_back(v[it]);
sort(as.begin(),as.end());
ld adg = 0;
for (int i = 0; i < k - m + 1; i++)
adg += as[i];
return adg;
}
int opt = 0;
for (int i = 1; i < ids.size(); i++)
{
int bt = better(ids[i],ids[opt],pos - 1);
if (bt == ids[i])
opt = i;
}
//cout << opt << ' ' << ids[opt] << endl;
ld pz = pos - 1;
ld adg = b[ids[opt]] / pz;
vector<int>newids;
for (int i = 0; i < opt; i++)
newids.push_back(ids[i]);
for (int i = opt + 1; i < ids.size(); i++)
newids.push_back(ids[i]);
return adg + solve(pos + 1,newids);
}
signed main()
{
cin >> n >> k;
for (int i = 1; i <= n; i++)
cin >> a[i] >> b[i];
for (int i = 1; i <= n; i++)
if (b[i] == -1)
b[i] = 1e9;
ld ans = 1e9;
for (m = 1; m <= k; m++)
{
///m oameni workpower, apoi doar merg prin orase
for (int i = 1; i <= n; i++)
v[i] = a[i] / m;
vector<int>ids;
for (int i = 1; i <= n; i++)
ids.push_back(i);
ld cur = solve(2,ids);
//cout << cur << endl;
ans = min(ans,cur);
}
cout << setprecision(5) << fixed;
cout << ans;
return 0;
}
Compilation message
Main.cpp: In function 'ld solve(long long int, std::vector<long long int>)':
Main.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (int i = 1; i < ids.size(); i++)
| ~~^~~~~~~~~~~~
Main.cpp:49:29: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
49 | for (int i = opt + 1; i < ids.size(); i++)
| ~~^~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
16 ms |
800 KB |
Output is correct |
6 |
Correct |
87 ms |
1352 KB |
Output is correct |
7 |
Correct |
334 ms |
2200 KB |
Output is correct |
8 |
Correct |
680 ms |
2648 KB |
Output is correct |
9 |
Correct |
826 ms |
2800 KB |
Output is correct |
10 |
Correct |
607 ms |
2572 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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
16 ms |
800 KB |
Output is correct |
6 |
Correct |
87 ms |
1352 KB |
Output is correct |
7 |
Correct |
334 ms |
2200 KB |
Output is correct |
8 |
Correct |
680 ms |
2648 KB |
Output is correct |
9 |
Correct |
826 ms |
2800 KB |
Output is correct |
10 |
Correct |
607 ms |
2572 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
125 ms |
1556 KB |
Output is correct |
13 |
Correct |
131 ms |
1784 KB |
Output is correct |
14 |
Correct |
124 ms |
1596 KB |
Output is correct |
15 |
Correct |
610 ms |
2716 KB |
Output is correct |
16 |
Correct |
603 ms |
2584 KB |
Output is correct |
17 |
Correct |
621 ms |
2612 KB |
Output is correct |
18 |
Correct |
835 ms |
2676 KB |
Output is correct |
19 |
Correct |
834 ms |
2760 KB |
Output is correct |
20 |
Correct |
840 ms |
2768 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
8 |
Correct |
1 ms |
348 KB |
Output is correct |
9 |
Correct |
0 ms |
348 KB |
Output is correct |
10 |
Correct |
1 ms |
348 KB |
Output is correct |
11 |
Correct |
0 ms |
348 KB |
Output is correct |
12 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
842 ms |
2676 KB |
Output isn't correct |
2 |
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 |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
16 ms |
800 KB |
Output is correct |
6 |
Correct |
87 ms |
1352 KB |
Output is correct |
7 |
Correct |
334 ms |
2200 KB |
Output is correct |
8 |
Correct |
680 ms |
2648 KB |
Output is correct |
9 |
Correct |
826 ms |
2800 KB |
Output is correct |
10 |
Correct |
607 ms |
2572 KB |
Output is correct |
11 |
Correct |
1 ms |
348 KB |
Output is correct |
12 |
Correct |
125 ms |
1556 KB |
Output is correct |
13 |
Correct |
131 ms |
1784 KB |
Output is correct |
14 |
Correct |
124 ms |
1596 KB |
Output is correct |
15 |
Correct |
610 ms |
2716 KB |
Output is correct |
16 |
Correct |
603 ms |
2584 KB |
Output is correct |
17 |
Correct |
621 ms |
2612 KB |
Output is correct |
18 |
Correct |
835 ms |
2676 KB |
Output is correct |
19 |
Correct |
834 ms |
2760 KB |
Output is correct |
20 |
Correct |
840 ms |
2768 KB |
Output is correct |
21 |
Correct |
1 ms |
344 KB |
Output is correct |
22 |
Correct |
0 ms |
348 KB |
Output is correct |
23 |
Correct |
1 ms |
348 KB |
Output is correct |
24 |
Correct |
0 ms |
348 KB |
Output is correct |
25 |
Correct |
0 ms |
348 KB |
Output is correct |
26 |
Correct |
0 ms |
348 KB |
Output is correct |
27 |
Correct |
0 ms |
348 KB |
Output is correct |
28 |
Correct |
1 ms |
348 KB |
Output is correct |
29 |
Correct |
0 ms |
348 KB |
Output is correct |
30 |
Correct |
1 ms |
348 KB |
Output is correct |
31 |
Correct |
0 ms |
348 KB |
Output is correct |
32 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
33 |
Halted |
0 ms |
0 KB |
- |