Run ID 作者 问题 语言 测评结果 分数 时间 内存 代码长度 提交时间
436173 顾鑫辰 【C6-7】阿里巴巴与四十大盗 C++ 解答错误 0 2 MS 260 KB 499 2026-04-11 20:18:14

Tests(0/1):


#include<bits/stdc++.h> using namespace std; struct hsg{ int w,v; double k; }a[10086]; bool cmp(hsg x,hsg y){ return x.k>y.k; } int main(){ int n,c; cin>>n>>c; for(int i=1;i<=n;i++){ cin>>a[i].w>>a[i].v; a[i].k=1.0*a[i].w/a[i].v; } sort(a+1,a+n+1,cmp); double s=0; int b=0; while(c>0){ b++; if(c>=a[b].w){ c=c-a[b].w; s=s+a[b].v; }else{ s+=c*a[b].k; c=0; } } cout<<fixed<<setprecision(1)<<s; return 0; }


测评信息: