为什么20分??
查看原帖
为什么20分??
1157267
jngrkek11楼主2024/3/30 09:51
#include<bits/stdc++.h>
	using namespace std;
	long long n,t,d; double e;
	struct f{
	int m,v; double l;
	}s[101];
	bool cmp(f a,f b){
	return a.l>b.l;
	}	
	int main(){
		ios::sync_with_stdio(false);
		cin.tie(0);
		cout.tie(0);
		cin>>n>>t;
		for(int i=0;i<n;i++){
			cin>>s[i].m>>s[i].v;
			s[i].l=s[i].v/s[i].m;
		}
		sort(s,s+n,cmp);
		for(int i=0;i<n;i++){
			if(s[i].m<=t){
				t-=s[i].m;
				e+=s[i].v;
			}
			else{
				e+=s[i].l*t;
				break;
			}
		}
		cout<<fixed<<setprecision(2)<<e;
	}
2024/3/30 09:51
加载中...