#include<bits/stdc++.h> using namespace std; struct node{ double x,y; }a[105]; bool cmp(struct node x,struct node y){ return x.y/x.x>y.y/y.x; } int main(){ int n,v; cin>>n>>v; int vi[n],wi[n]; for(int i=0;i<n;++i){ cin>>a[i].x>>a[i].y; } int d=0;double sum=0; sort(a,a+n,cmp); while(v-a[d].x>0){ sum+=a[d].y; v-=a[d].x; d++; } sum+=(a[d].y/a[d].x*v); printf("%.2lf",sum); return 0; } |
Double click to view unformatted code.