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>
#define ll long long
#define str string
#define ins insert
#define ld long double
#define pb push_back
#define pf push_front
#define pof pop_front()
#define pob pop_back()
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define fr first
#define sc second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define sz size()
#define vll vector<ll>
#define bc back()
#define arr array
#define pll vector<pair<ll,ll>>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll, null_type,less_equal<ll>, rb_tree_tag,tree_order_statistics_node_update>
template<class S,class T>
bool chmin(S &a,const T &b) {
return a>b?(a=b)==b:false;
}
template<class S,class T>
bool chmax(S &a,const T &b) {
return a<b?(a=b)==b:false;
}
//void fre(string s){freopen((s+".in").c_str(),"r",stdin);freopen((s+".out").c_str(),"w",stdout);}
void start(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
const ll inf=1e9;
const ll mod=1e9+7;
const ll N=1e3+7;
const ld eps=1e-9;
ld dp[N][N];
void solve(){
ll i,j;
ll n,k;
cin>>n>>k;
pll v(n);
for(i=0;i<n;i++){
cin>>v[i].sc>>v[i].fr;
if(v[i].fr==-1)v[i].fr=inf;
}
sort(all(v));
ll a[n+5],b[n+5];
for(i=1;i<=n;i++){
a[i]=v[i-1].sc;
b[i]=v[i-1].fr;
}
ld ans=0;
ll suf[n+5];;
vll vv;
for(i=1;i<=n;i++)vv.pb(a[i]);
sort(all(vv));
for(i=0;i<k;i++)ans+=vv[i];
for(ll m=1;m<=k;m++){
for(i=0;i<=n;i++){
for(j=0;j<=n;j++)dp[i][j]=inf;
}
dp[0][0]=0;
for(i=1;i<=k;i++){
for(j=0;j<=min(i,m);j++){
if(j && b[i]<inf) chmin( dp[i][j] , dp[i-1][j-1] + (ld)b[i]/(ld)j);
chmin(dp[i][j],dp[i-1][j]+(ld)a[i]/(ld)(m+1));
if(j==m){
vll v;
for(ll q=i+1;q<=n;q++)v.pb(a[q]);
sort(all(v));
ll sum=0;
for(ll q=0;q<k-i;q++) sum+=v[q];
chmin(ans,dp[i][j]+(ld)sum/(ld)(m+1));
}
}
}
}
cout<<fixed<<setprecision(15)<<ans<<endl;
}
signed main(){
start();
ll t=1;
//cin>>t;
while(t--) solve();
return 0;
}
/*
3 1 5
2 2
3 2
2 2
3 2
10
*/
Compilation message (stderr)
Main.cpp: In function 'void solve()':
Main.cpp:63:8: warning: unused variable 'suf' [-Wunused-variable]
63 | ll suf[n+5];;
| ^~~
# | 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... |