#pragma GCC target ("avx2")
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#include<bits/stdc++.h>
#include<math.h>
using namespace std;
typedef int ll;
typedef float ld;
typedef pair<ll, ll> pl;
typedef vector<ll> vl;
#define FD(i, r, l) for(ll i = r; i > (l); --i)
#define K first
#define V second
#define G(x) ll x; cin >> x;
#define GD(x) ld x; cin >> x;
#define GS(s) string s; cin >> s;
#define EX(x) { cout << x << '\n'; exit(0); }
#define A(a) (a).begin(), (a).end()
#define F(i, l, r) for (ll i = l; i < (r); ++i)
#define NN 510
#define M 1000000007 // 998244353
vector<pl> votes;
ll n, k;
ll take;
ld dp[2][NN][NN]; //
ll op, np;
ld rec(ll i, ll bs, ll vots, bool old) {
if (i == n) return vots + bs >= k and bs >= take ? 0: 1e9;
if (old) return dp[op][bs][vots];
auto &DP = dp[np][bs][vots];
DP = 1e9;
DP = min(DP, rec(i+1, bs, vots, 1));
DP = min(DP, rec(i+1, bs, vots+1, 1) + ld(votes[i].V)/(1 + take));
if (~votes[i].K) DP = min(DP, rec(i+1, bs+1, vots, 1) + ld(votes[i].K)/(1 + bs));
return DP;
}
ld cache[510];
ld q(ll idx) {
take = idx;
if (idx < 0 || idx > n) return 1e9;
if (cache[idx] == cache[idx]) return cache[idx];
op = 0, np = 1;
FD(i, n-1, -1) {
F(bs, 0, n+1) F(vots, 0, n+1) rec(i, bs, vots, 0);
swap(op, np);
}
auto ans = dp[op][0][0];
// cout << idx << "WTF " << ans << endl;
return cache[idx] = ans;
}
int main(){
// freopen("a.in", "r", stdin);
// freopen("a.out", "w", stdout);
ios_base::sync_with_stdio(false); cin.tie(0);
cout << fixed << setprecision(20);
cin >> n >> k;
votes.resize(n);
for (auto &[b, a]: votes) {
cin >> a >> b;
}
memset(cache, -1, sizeof cache);
sort(A(votes));
ld ans = 1e9;
ll l = -1, r = n;
while (l+1<r) {
ll mid = (l+r)/2;
if (q(mid) < q(mid+1)) l = mid;
else r = mid;
}
F(th, l-2, l+3) ans = min(ans, q(th));
// F(i, 0, n+1) ans = min(ans, q(i));
cout << ans << endl;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
Execution timed out |
2566 ms |
2396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
Execution timed out |
2566 ms |
2396 KB |
Time limit exceeded |
6 |
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 |
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 |
Execution timed out |
2537 ms |
2396 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 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 |
Execution timed out |
2566 ms |
2396 KB |
Time limit exceeded |
6 |
Halted |
0 ms |
0 KB |
- |