This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// while (clock()<=69*CLOCKS_PER_SEC)
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("O3")
// #pragma GCC target ("avx2")
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x) \
sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
{
sim > struct rge {
c b, e;
};
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef XOX
~debug()
{
cerr << endl;
}
eni(!=) cerr << boolalpha << i;
ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d)
{
ris << "" << d.first << " --> " << d.second << "";
}
sim dor(rge<c> d)
{
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c &)
{
ris;
}
#endif
}
;
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#ifdef XOX
#warning Times may differ!!!
#endif
#define endl '\n'
#define pb emplace_back
#define vt vector
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
const int nax = 1000 * 1007, mod = 1e9 + 7;
int main()
{
cin.tie(0)->sync_with_stdio(0);
int n, k;
cin >> n >> k;
vt<pii> wek(n);
for (auto &[a, b] : wek) {
cin >> a >> b;
if (b == -1) b = mod;
}
sort(all(wek), [](const pii &a, const pii &b) {
return a.second < b.second;
});
typedef double T;
auto solve_for = [&](int m) {
vt<vt<T>> dp(n + 1, vt<T>(k - m + 1, mod));
dp[0][0] = 0.;
for (int i = 0; i < n; i++) {
for (int j = 0; j <= k - m; j++) {
int bylo = i - j;
if (j < k - m) dp[i + 1][j + 1] = min(dp[i + 1][j + 1], dp[i][j] + (T)wek[i].first / (m + 1));
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + (bylo >= m ? 0. : (T)wek[i].second / (bylo + 1)));
}
}
return dp[n][k - m];
};
int a = 0, b = k;
while (b - a >= 3) {
int p_1 = a + (b - a) / 3;
int p_2 = b - (b - a) / 3;
assert(p_1 != p_2);
if (solve_for(p_1) <= solve_for(p_2)) b = p_2;
else a = p_1;
}
T ans = mod;
for (int i = 0; i <= k; i++) {
debug() << imie(i) imie(solve_for(i));
}
debug() << imie(a) imie(b);
for (int i = a; i <= b; i++) {
ans = min(ans, solve_for(i));
}
cout << fixed << setprecision(15) << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |