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 fi first
#define se second
#define p(x,y) pair<ll,ll>(x,y)
#define BIT(i,x) ((x>>i)&1)
#define MASK(x) (1<<x)
#define ld long double
#define __builtin_popcount __builtin_popcountll
#define pll pair<ll,ll>
template<class T1,class T2>
bool maximize(T1 &x,const T2 &y)
{
if(x<y)
{
x=y;
return 1;
}
return 0;
}
template<class T1,class T2>
bool minimize(T1 &x,const T2 &y)
{
if(x>y)
{
x=y;
return 1;
}
return 0;
}
void online()
{
std::ios_base::sync_with_stdio(0);
cin.tie(0);
#ifdef thuc
freopen("input.inp", "r", stdin);
freopen("output.out","w", stdout);
#else
#endif
}
const ll N=5e2+10;
ll n,k;
pair<ld,ld> a[N];
ld f[N][N];
int main()
{
online();
cin>>n>>k;
for(int i=1;i<=n;i++)
{
cin>>a[i].se;
cin>>a[i].fi;
if(a[i].fi==-1) a[i].fi=1e12;
}
sort(a+1,a+n+1);
ld ans=1e15;
for(int t=0;t<=k;t++)
{
for(int i=1;i<=n;i++)
{
for(int j=0;j<=n;j++) f[i][j]=1e15;
}
f[0][0]=0;
for(int i=0;i<n;i++)
{
for(int j=0;j<=i;j++)
{
if(i-j>=t) minimize(f[i+1][j],f[i][j]);
minimize(f[i+1][j],f[i][j]+(a[i+1].fi/(ld)(i-j+1)));
minimize(f[i+1][j+1],f[i][j]+(a[i+1].se/(ld)(t+1)));
}
}
minimize(ans,f[n][k-t]);
}
cout<<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... |