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;
using ll = long long;
#define fi first
#define si second
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef tuple<int,int,int> ti;
template<typename T> bool chmin(T &a, T b){return (b < a) ? a = b, 1 : 0;}
template<typename T> bool chmax(T &a, T b){return (b > a) ? a = b, 1 : 0;}
void debug_out() {cerr<<endl;}
template <typename Head, typename... Tail>
void debug_out(Head _H, Tail... _T) {cerr<<" "<<to_string(_H);debug_out(_T...);}
#define debug(...) cerr<<"["<<#__VA_ARGS__<<"]:",debug_out(__VA_ARGS__)
const int N = 510;
const double INF=1e9;
int n,k,cnt;
double dp[N][N];
pd arr[N];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin.exceptions(ios::badbit|ios::failbit);
cin >> n >> k;
for (int i = 1; i <= n; ++i) {
cin >> arr[i].si >> arr[i].fi;
if (arr[i].fi==-1) arr[i].fi=INF;
}
double ans = INF;
sort(arr+1,arr+1+n);
for (int m = 0; m <= k; ++m) { //no. collab
for (int i = 0; i <= n; ++i) for (int j = 0; j <= n; ++j) {
dp[i][j]=INF;
}
dp[0][0]=0;
for (int i = 1; i <= n; ++i) {
for (int j = 0; j <= i; ++j) { //no. non collab
double va = arr[i].si/(m+1);
double vb = arr[i].fi/min(i-j,m);
chmin(dp[i][j],dp[i-1][j]+vb);
if (i-j>m) chmin(dp[i][j],dp[i-1][j]);
if (j) chmin(dp[i][j],dp[i-1][j-1]+va);
}
}
chmin(ans,dp[n][k-m]);
}
cout << fixed << setprecision(10);
cout << ans;
return 0;
}
# | 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... |