全部评论 1

  • #include<iostream>
    #include<algorithm>
    #include<vector>
    #include<cstdio>
    using namespace std;
    int n,c;
    struct node{
        double kg,money;
    }grass[110];
    bool cmp(node x,node y){
        return x.money/x.kg > y.money/y.kg;
    }
    int main(){
        cin>>n>>c;
        for(int i = 1;i<=n;i++) cin>>grass[i].kg>>grass[i].money;
        sort(grass+1,grass+n+1,cmp);
        double ans = 0;
        for(int i = 1;c>0;i++){
            if(c>=grass[i].kg){
                ans+=grass[i].money;
                c-=grass[i].kg;
            }
            else{
                ans+=grass[i].money/grass[i].kg*c;
                c = 0;
            }
        }
        printf("%.2f",ans);
        return 0;
    }
    

    2024-08-13 来自 浙江

    0
首页