标签:style blog io color ar os sp for 数据
1 3 15 5 10 2 8 3 9
65
#include<stdio.h> #include<string.h> #include<algorithm> using namespace std; struct st { int a,b; }data[20]; int cmp(st x,st y) { return x.a>y.a; } int main() { int i,j,v,w,test; int sum,k; scanf("%d",&test); while(test--) { scanf("%d %d",&v,&w); for(i=1;i<=v;i++) { scanf("%d %d",&data[i].a,&data[i].b); } sort(data+1,data+v+1,cmp); for(i=1,sum=0;i<=v;i++) { k=data[i].a*data[i].b; if(w-data[i].b>=0) { sum+=k; w-=data[i].b; } else { sum+=w*data[i].a; break; } } printf("%d\n",sum); } return 0; }
标签:style blog io color ar os sp for 数据
原文地址:http://blog.csdn.net/hdd871532887/article/details/40932245