#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 = 1e13;
ll n, k;
vector<vector<ld> > dp; // dp[use city until][count vote w/o collab]
pi city[505];
int main()
{
ld ans = INF;
input2(n, k);
ll kk = n;
for (ll i=1; i<=n; ++i) {input2(city[i].s, city[i].f); if (city[i].f==-1) {city[i].f = INF;k--;} }
sort(city+1, city+n+1);
for (ll i=0; i<=min(kk, k); ++i)
{
dp.assign(n+1, vector<ld> (n+1, INF));
dp[0][0] = 0;
for (ll j=1; j<=n; ++j)
{
for (ll x=0; x<=j; ++x)
{
if (j-x <= i) // still keep the streak
{
if (x) dp[j][x] = min(dp[j][x], dp[j-1][x-1] + ld(ld(city[j].s)/(ld(i+1)))); // choose w/o collab
dp[j][x] = min(dp[j][x], dp[j-1][x] + ld(ld(city[j].f)/ld(j-x))); // choose w collab
}
else
{
dp[j][x] = dp[j-1][x]; // dont choose
if (x) dp[j][x] = min(dp[j][x], dp[j-1][x-1] + ld(ld(city[j].s)/ld(i+1))); // choose w/o collab
}
}
}
ans = min(ans, dp[n][k-i]);
}
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:45:2: note: in expansion of macro 'input2'
45 | 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:47:28: note: in expansion of macro 'input2'
47 | for (ll i=1; i<=n; ++i) {input2(city[i].s, city[i].f); if (city[i].f==-1) {city[i].f = INF;k--;} }
| ^~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
654 ms |
4372 KB |
Output is correct |
2 |
Correct |
600 ms |
4184 KB |
Output is correct |
3 |
Correct |
699 ms |
4380 KB |
Output is correct |
4 |
Correct |
691 ms |
4376 KB |
Output is correct |
5 |
Correct |
637 ms |
4380 KB |
Output is correct |
6 |
Correct |
623 ms |
4376 KB |
Output is correct |
7 |
Correct |
665 ms |
4380 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |