This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define int ll
#define pii pair<ll, ll>
#define f first
#define s second
#define REP(i,n) for (int i = 0; i<n; ++i)
#define REP1(i,n) for (int i = 1; i<=n; ++i)
#define SZ(x) (int)((x).size())
#define ALL(x) (x).begin(), (x).end()
#define pb push_back
#define MX(a,b) a = max(a,b)
#define MN(a,b) a = min(a,b)
#ifdef BALBIT
#define bug(...) cerr<<"#"<<__LINE__<<" "<<#__VA_ARGS__<<" - ", _do(__VA_ARGS__)
template <typename T> void _do( T && x) {cerr<<x<<endl;}
template <typename T, typename ...S> void _do( T && x, S && ...y) {cerr<<x<<", "; _do(y...);}
#else
#define bug(...)
#define endl '\n'
#endif // BALBIT
const int maxn = 500+5;
const ll inf = 1ll<<62;
int A[maxn], B[maxn];
double dp[maxn][maxn];
ll mnsum[maxn];
signed main(){
ios::sync_with_stdio(0), cin.tie(0);
bug(1,2);
int n, k; cin>>n>>k;
vector<pii> bo(n);
REP(i,n) {
cin>>bo[i].s>>bo[i].f;
if (bo[i].f == -1) bo[i].f = inf;
}
sort(ALL(bo));
REP1(i,n) {
A[i] = bo[i-1].s; B[i] = bo[i-1].f;
bug(i,A[i],B[i]);
}
vector<ll> tmp;
for (int i = n; i>=1; --i) {
tmp.pb(A[i]);
int need = k-i+1;
sort(ALL(tmp));
REP(j, need) mnsum[i] += tmp[j];
bug(i, mnsum[i]);
}
double re = inf;
for (int TC = 1; TC <=k; ++TC) {
// total number of collaborators + 1
REP(i, maxn) fill(dp[i], dp[i]+maxn, inf);
dp[0][1] = 0;
REP1(i,n) {
REP1(t, TC+1) {
if (t>1) MN(dp[i][t], dp[i-1][t-1] + B[i] / (double)(t-1));
MN(dp[i][t], dp[i-1][t] + A[i] / (double)(TC));
}
MN(re, dp[i][TC] + mnsum[i+1] / (double)TC);
}
}
cout<<fixed<<setprecision(10)<<re<<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... |