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 pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
bool comp(pair<ll,ll>a,pair<ll,ll>b){
if(a.ss<b.ss) return true;
if(a.ss>b.ss) return false;
return a.ff<b.ff;
}
int main(){
ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
ll N,K;
cin>>N>>K;
pair<ll,ll>p[N+5];
for(ll i=1;i<=N;i++){
cin>>p[i].ff>>p[i].ss;
if(p[i].ss==-1) p[i].ss=1e6;
}
sort(p+1,p+N+1,comp);
double dp[N+5][N+5][N+5],ans=1e9;
for(ll goal=0;goal<=K;goal++){
for(ll i=0;i<=N;i++){
for(ll j=0;j<=N;j++){
for(ll k=0;k<=N;k++){
dp[i][j][k]=1e9;
}
}
}
dp[0][0][0]=0;
for(ll i=0;i<N;i++){
for(ll j=0;j<=K;j++){
for(ll k=0;k<=goal;k++){
dp[i+1][j][k]=min(dp[i+1][j][k],dp[i][j][k]);
dp[i+1][j+1][k]=min(dp[i+1][j+1][k],dp[i][j][k]+(double)p[i+1].ff/(goal+1));
dp[i+1][j+1][k+1]=min(dp[i+1][j+1][k+1],dp[i][j][k]+(double)p[i+1].ss/(k+1));
}
}
}
ans=min(ans,dp[N][K][goal]);
}
printf("%.10f",ans);
}
# | 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... |