#include <bits/stdc++.h>
//#include "bits_stdc++.h"
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define endl '\n'
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define input(x) scanf("%lld", &x);
#define input2(x, y) scanf("%lld%lld", &x, &y);
#define input3(x, y, z) scanf("%lld%lld%lld", &x, &y, &z);
#define input4(x, y, z, a) scanf("%lld%lld%lld%lld", &x, &y, &z, &a);
#define print(x, y) printf("%lld%c", x, y);
#define show(x) cerr << #x << " is " << x << endl;
#define show2(x,y) cerr << #x << " is " << x << " " << #y << " is " << y << endl;
#define show3(x,y,z) cerr << #x << " is " << x << " " << #y << " is " << y << " " << #z << " is " << z << endl;
#define all(x) x.begin(), x.end()
#define discretize(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define FOR(i, x, n) for (ll i =x; i<=n; ++i)
#define RFOR(i, x, n) for (ll i =x; i>=n; --i)
using namespace std;
mt19937_64 rnd(chrono::steady_clock::now().time_since_epoch().count());
//using namespace __gnu_pbds;
//#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
//#define ordered_multiset tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<ld, ll> pd;
typedef pair<string, ll> psl;
typedef pair<ll, ll> pi;
typedef pair<pi, ll> pii;
typedef pair<pi, pi> piii;
ld const INF = 1e16;
ll n, k;
ld dp[505][505][505]; // dp[using city until][no.of conllaborator][count vote]
pi city[505];
int main()
{
input2(n, k);
for (ll i=1; i<=n; ++i) {input2(city[i].s, city[i].f); if (city[i].f==-1) city[i].f = INF;}
sort(city+1, city+n+1);
for (ll x=0; x<=n; ++x) for (ll i=0; i<=n; ++i) for (ll j=0; j<=n; ++j) dp[x][i][j] = INF;
dp[0][0][0] = 0;
for (ll i=1; i<=n; ++i)
{
for (ll j=0; j<=i; ++j)
{
for (ll x = 0; x<=min(i, k); ++x)
{
dp[i][j][x] = dp[i-1][j][x];
if (j && x) dp[i][j][x] = min(dp[i][j][x], dp[i-1][j-1][x-1] + ld(ld(city[i].f)/(ld(j))));
if (x) dp[i][j][x] = min(dp[i][j][x], dp[i-1][j][x-1] + ld(ld(city[i].s)/ld(j+1)));
}
}
}
ld ans = INF;
for (ll i=0; i<=n; ++i) ans = min(ans, dp[n][i][k]);
cout << setprecision(15) << fixed << ans << endl;
return 0;
}
Compilation message
Main.cpp: In function 'int main()':
Main.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:44:2: note: in expansion of macro 'input2'
44 | input2(n, k);
| ^~~~~~
Main.cpp:13:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define input2(x, y) scanf("%lld%lld", &x, &y);
| ~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:45:28: note: in expansion of macro 'input2'
45 | for (ll i=1; i<=n; ++i) {input2(city[i].s, city[i].f); if (city[i].f==-1) city[i].f = INF;}
| ^~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
590 ms |
1048580 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
590 ms |
1048580 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
1 ms |
14684 KB |
Output is correct |
3 |
Correct |
1 ms |
14784 KB |
Output is correct |
4 |
Correct |
1 ms |
14684 KB |
Output is correct |
5 |
Correct |
1 ms |
14684 KB |
Output is correct |
6 |
Correct |
1 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14680 KB |
Output is correct |
9 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
1 ms |
14684 KB |
Output is correct |
3 |
Correct |
1 ms |
14784 KB |
Output is correct |
4 |
Correct |
1 ms |
14684 KB |
Output is correct |
5 |
Correct |
1 ms |
14684 KB |
Output is correct |
6 |
Correct |
1 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14680 KB |
Output is correct |
9 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
14684 KB |
Output is correct |
2 |
Correct |
1 ms |
14684 KB |
Output is correct |
3 |
Correct |
1 ms |
14784 KB |
Output is correct |
4 |
Correct |
1 ms |
14684 KB |
Output is correct |
5 |
Correct |
1 ms |
14684 KB |
Output is correct |
6 |
Correct |
1 ms |
14684 KB |
Output is correct |
7 |
Correct |
2 ms |
14684 KB |
Output is correct |
8 |
Correct |
2 ms |
14680 KB |
Output is correct |
9 |
Incorrect |
1 ms |
14684 KB |
Output isn't correct |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
510 ms |
1048576 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2396 KB |
Output is correct |
2 |
Correct |
0 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
6492 KB |
Output is correct |
4 |
Correct |
1 ms |
8540 KB |
Output is correct |
5 |
Runtime error |
590 ms |
1048580 KB |
Execution killed with signal 9 |
6 |
Halted |
0 ms |
0 KB |
- |