#include<bits/stdc++.h>
using namespace std;
int const N=1e3+10;
int n,k,a[N],b[N];
double c[N];
bool check(double mid){
for(int i=1;i<=n;i++){
c[i]=mid*b[i]-a[i];
}
sort(c+1,c+1+n);
double ans=0;
for(int i=1;i<=n-k;i++){
ans+=c[i];
}
return ans<=0;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
double L=0,R=100;
while(R-L>1e-4){
double mid=(L+R)/2.0;
if(check(mid)){
L=mid;
}
else{
R=mid;
}
}
printf("%.0lf",L*100);
return 0;
}#include<bits/stdc++.h>
using namespace std;
int const N=1e3+10;
int n,k,a[N],b[N];
double c[N];
bool check(double mid){
for(int i=1;i<=n;i++){
c[i]=mid*b[i]-a[i];
}
sort(c+1,c+1+n);
double ans=0;
for(int i=1;i<=n-k;i++){
ans+=c[i];
}
return ans<=0;
}
int main(){
cin>>n>>k;
for(int i=1;i<=n;i++){
cin>>a[i];
}
for(int i=1;i<=n;i++){
cin>>b[i];
}
double L=0,R=100;
while(R-L>1e-4){
double mid=(L+R)/2.0;
if(check(mid)){
L=mid;
}
else{
R=mid;
}
}
printf("%.0lf",L*100);
return 0;
}
逃避考试
最新推荐文章于 2024-08-14 11:57:07 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)