20pts求助!
查看原帖
20pts求助!
197600
张伟大律师楼主2023/9/30 18:52
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e7;
int main(){
    int N,T,m[maxn],v[maxn],r[maxn],cnt=0,value=0,t=0;
    cin>>N>>T;
    for(int i=0;i<N;i++){
        cin>>m[i]>>v[i];
        r[i]=v[i]/m[i];
    }
    for(int i=0;i<N;i++){//冒泡排序,利用性价比
        for(int j=1;j<N;j++){
            if(r[j]>r[j-1]){
                swap(m[j],m[j-1]);
                swap(v[j],v[j-1]);
                swap(r[j],r[j-1]);
            }
        }
    }
    while(true){
        if(cnt+m[t]>T)break;//跳出循环
        cnt=cnt+m[t];
        value=value+v[t];
        t++;
    }
    int rem=T-cnt;
    float REST=r[t]*rem;
    float ans=REST+value;
    cout << fixed << setprecision(2) << ans << endl;
    return 0;
}
2023/9/30 18:52
加载中...