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 speed ios_base::sync_with_stdio(0); cin.tie(0)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ldb;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=5e2+10,P=998244353;
const ll INF=0x3f3f3f3f,oo=0x3f3f3f3f3f3f3f3f;
ll n,k;
pair<ldb,ldb> vt[MAX];
ldb dp[MAX][MAX];
ldb suf[MAX][MAX];
int main() {
speed;
cin>>n>>k;
for (int i=1;i<=n;i++) {
cin>>vt[i].first>>vt[i].second;
if (vt[i].second==-1) vt[i].second=oo;
}
sort(vt+1,vt+n+1,[=](pair<ldb,ldb> a,pair<ldb,ldb> b){
if (a.second==b.second) return a.first>b.first;
return a.second<b.second;
});
memset(suf,0,sizeof(suf));
for (int i=1;i<=k;i++) {
dp[0][i]=oo;
suf[n+1][i]=oo;
}
dp[0][0]=0;
for (int i=1;i<=n;i++) {
dp[i][0]=0;
for (int j=1;j<=k;j++) {
dp[i][j]=min(dp[i-1][j-1]+vt[i].second/j,dp[i-1][j]);
// cout<<dp[i][j]<<" ";
}
// cout<<"\n";
}
suf[n+1][0]=0;
for (int i=n;i>=0;i--) {;
suf[i][0]=0;
for (int j=k;j>=1;j--) {
suf[i][j]=min(suf[i+1][j-1]+vt[i].first,suf[i+1][j]);
// cout<<i<<" "<<j<<" "<<suf[i+1][j-1]+vt[i].first<<" "<<suf[i+1][j]<<" "<<suf[i][j]<<" suf\n";
}
}
ldb ans=oo;
for (int i=0;i<=n;i++) {
for (int j=k;j>=0;j--) {
ans=min(ans,dp[i][j]+suf[i+1][k-j]/(j+1));
// cout<<i<<" "<<j<<" "<<dp[i][j]<<" "<<suf[i+1][k-j]<<"\n";
}
// cout<<"\n";
}
cout<<fixed<<setprecision(20)<<ans<<"\n";
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... |