菜雞PAT刷題記錄:1020月餅
阿新 • • 發佈:2020-12-10
技術標籤:筆記
測試點二考察的是庫存量要為float型別。
測試點三考察的是市場最大需求量大於庫存量時,直接輸出所有的收益和。
#include<iostream>
#include<vector>
#include<iomanip>
using namespace std;
int main(){
int n,d;
cin>>n>>d;
float a[n],b[n];
float test=0.0,testsum=0.0;
for(int i=0;i<n;i++) {cin>> a[i];test+=a[i];}
for(int i=0;i<n;i++) {cin>>b[i];testsum+=b[i];}
float sum=0.00,c[n];
float temp=(float)d;
for(int i=0;i<n;i++) c[i]=b[i]/(a[i]*1.0);
vector<int> tem(n);
if(test<d){
temp=0;
sum=testsum;
}
while(temp){
int max=0;
float underline=0.0;
for(int i=0;i<n;i++){
if(c[i]>=underline & tem[i]!=1){underline=c[i];max=i;}
}
if(temp>a[max]){
temp-=a[max];
sum+=b[max];
}
else{
sum+=temp/(a[max]*1.0)*b[max];
temp= 0;
}
tem[max]=1;
}
cout<<fixed<<setprecision(2)<<sum<<endl;
}