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 ull unsigned long long
#define pb(e) push_back(e)
#define sv(a) sort(a.begin(),a.end())
#define sa(a,n) sort(a,a+n)
#define mp(a,b) make_pair(a,b)
#define vf first
#define vs second
#define ar array
#define all(x) x.begin(),x.end()
const int inf = 0x3f3f3f3f;
const int mod = 1000000007;
const double PI=3.14159265358979323846264338327950288419716939937510582097494459230;
bool remender(ll a , ll b){return a%b;}
//freopen("problemname.in", "r", stdin);
//freopen("problemname.out", "w", stdout);
bool cmp(pair<int,int> a , pair<int,int> b){
if(a.vs == -1)return 0;
if(b.vs == -1)return 1;
if(a.vs != b.vs)return a.vs < b.vs;
return a.vf < b.vf;
}
const int N = 503;
int pre[N][N];
vector<pair<int,int>> v;
double dp[N][N];
int n , k;
double find(int x){
if(x == 0)return pre[0][k-1];
for(int i = 0; i <= n; i++){
for(int j = 0; j <= n; j++)dp[i][j] = 1e9;
}
dp[0][0] = 0.0;
double res = 1e9;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= min(i,x); j++){
if(v[i-1].vs == -1){
goto h;
}
if(j == 0){
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
continue;
}
if(j == x){
int rem = k - i;
res = min(res , dp[i-1][j-1] + (double)v[i-1].vs/(double)j + (rem > 0 ? (double)pre[i][rem-1]/(double)(x+1) : 0));
dp[i][j] = dp[i-1][j] + (double)v[i-1].vf/(double)(x+1);
}
else {
dp[i][j] = min(dp[i-1][j-1] + (double)v[i-1].vs/(double)j , dp[i-1][j] + (double)v[i-1].vf/(double)(x+1));
}
}
}
h:
return res;
}
void solve(){
cin >> n >> k;
int cnt = 0;
for(int i = 0; i < n; i++){
int x , y;
cin >> x >> y;
v.pb(mp(x,y));
if(y != -1)cnt++;
}
sort(all(v), cmp);
vector<int> tp;
for(int i = n - 1; i >= 0; i--){
tp.pb(v[i].vf);
sv(tp);
int cur = 0 , sum = 0;
for(int j = i; j < n; j++){
sum += tp[cur];
pre[i][cur] = sum;
cur++;
}
}
if(cnt == 0){
cout << pre[0][k-1] << '\n';
return;
}
double ans = 1e9;
for(int i = 0; i <= cnt; i++){
ans = min(ans , find(i));
}
cout << setprecision(10) << ans << '\n';
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
//int t;cin >> t;while(t--)
solve();
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... |