标签:
#include<iostream> #include<algorithm> using namespace std; struct wp { int value; int weight; }; int cmp(wp a,wp b) { return a.value>b.value; } int main() { wp a[11]; int T,i,n,m,sum; cin>>T; while(T--) { sum=0; cin>>n>>m; for(i=0;i<n;i++) cin>>a[i].value>>a[i].weight; sort(a,a+n,cmp); for(i=0;i<n;i++) { if(a[i].weight<=m) { sum+=a[i].value*a[i].weight; m-=a[i].weight; } else { sum+=m*a[i].value; break; } } cout<<sum<<endl; } return 0; }
标签:
原文地址:http://blog.csdn.net/zuguodexiaoguoabc/article/details/45438937