This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#define here cerr<<"===========================================\n"
#define dbg(x) cerr<<#x<<": "<<x<<endl;
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define ld double
#define ll long long
#define llinf 100000000000000000LL // 10^17
#define pb push_back
#define popb pop_back
#define fi first
#define sc second
#define endl '\n'
#define pll pair<ll,ll>
#define pld pair<ld,ld>
#define sz(a) (ll)(a.size())
#define all(a) a.begin(),a.end()
#define ceri(a,l,r) {cerr<<#a<<": ";for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
#define daj_mi_malo_vremena ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
using namespace std;
using namespace __gnu_pbds;
/*
ll add(ll x,ll y){
x+=y;
if(x<0){
x%=mod;
x+=mod;
}else{
if(x>=mod) x%=mod;
}
return x;
}
ll mul(ll a,ll b){
ll ans = (a*b)%mod;
if(ans<0) ans+=mod;
return ans;
}
typedef tree<int,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
typedef tree<int,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_multiset;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rnd(ll l,ll r){
return uniform_int_distribution<ll>(l,r)(rng);
}
*/
#define maxn 505
ll n,k;
ll calc[maxn][maxn];
ld dp[maxn][maxn];
pll a[maxn];
bool cmp(pll a,pll b){
if(a.sc!=b.sc) return a.sc<b.sc;
return a.fi>b.fi;
}
int main(){
daj_mi_malo_vremena
cout<<fixed<<setprecision(30);
cerr<<fixed<<setprecision(30);
cin >> n >> k;
for(ll i = 1;i<=n;i++) cin >> a[i].fi >> a[i].sc;
for(ll i = 1;i<=n;i++) if(a[i].sc==-1) a[i].sc = 2000;
sort(a+1,a+1+n,cmp);
for(ll i = 0;i<=n+1;i++) for(ll j = 0;j<=n+1;j++) dp[i][j] = calc[i][j] = llinf;
calc[n+1][0] = 0;
for(ll i = n;i>=1;i--){
calc[i][0] = 0;
for(ll j = 1;j<=n;j++) calc[i][j] = min(calc[i+1][j],calc[i+1][j-1]+a[i].fi);
}
ld ans = llinf;
dp[0][0] = 0;
for(ll e = 0;e<=k;e++){
for(ll i = 1;i<=n;i++){
dp[0][0] = 0;
for(ll j = 0;j<=e;j++){
dp[i][j] = dp[i-1][j] + 1.0*a[i].fi/(e+1);
if(a[i].sc!=2000&&j) dp[i][j] = min(dp[i][j],dp[i-1][j-1]+1.0*a[i].sc/j);
}
}
for(ll i = e;i<=k;i++) ans = min(ans,dp[i][e]+1.0*calc[i+1][k-i]/(e+1));
}
cout<<ans<<endl;
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... |