Run ID | Author | Problem | Lang | Verdict | Time | Memory | Code Length | Submit Time |
---|---|---|---|---|---|---|---|---|
35123 | YOYOLEE-李昕颖 | 金银岛 | C++ | Wrong Answer | 0 MS | 256 KB | 570 | 2023-12-26 20:44:18 |
#include<iostream> #include<iomanip> #include<algorithm> using namespace std; struct s{ int n,v; }a[10005]; double h[105],c; bool cmp(int A,int B){ return h[A]>h[B]; } int w,s,k; int main(){ cin>>k; for(int i=0;i<k;i++){ cin>>w>>s; for(int j=1;j<=s;j++){ cin>>a[j].n>>a[j].v; h[i]=a[j].v*1.0/a[j].n; } sort(h+1,h+1+s,cmp); for(int j=1;j<=s;j++){ if(w>=a[j].n){ w-=a[j].n; c+=a[j].v*1.0; } else { c+=a[j].v*1.0/a[j].n*w; } } cout<<fixed<<setprecision(2)<<c; cout<<endl; } return 0; }