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 int long long
#define fi first
#define se second
#define pb push_back
#define debug(x) cout<<#x<<": "<<x<<"\n"
signed main()
{
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
// freopen("input.000","r",stdin);
// freopen("output.000","w",stdout);
// srand((unsigned)time(NULL));
// rand()
int n,a[505],b[505],size_a,size_b,i,k,x,y;
long double sum,ans;
cin>>n>>k;size_a=size_b=0;
for (i=1;i<n+1;i++)
{
cin>>x>>y;
if (y!=-1)
{
size_a++;
a[size_a]=x;
}
else
{
size_b++;
b[size_b]=x;
}
}
sort(a+1,a+size_a+1);
sort(b+1,b+size_b+1);
ans=1e9;
for (x=0;x<=k;x++) if (x<=size_a and k-x<=size_b)
{
sum=0;
for (i=1;i<x+1;i++) sum+=(double)a[i]/i;
for (i=1;i<=k-x;i++) sum+=(double)b[i]/(x+1);
ans=min(ans,sum);
}
cout<<fixed<<setprecision(4)<<ans<<"\n";
}
# | 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... |