2 2 3 1 2 3 0
5 经过锦囊相助,HDU会脱离危机吗? 欲知后事如何,且听下回分解——
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
struct jewelry{
int num,value;
double ratio;
};
jewelry my[111];
bool comp(jewelry a,jewelry b){
return a.value>b.value;
}
int main(){
int v,n;
while(cin>>v>>n&&v){
int i,j;
for(i=0;i<n;++i){
cin>>my[i].value>>my[i].num;
}
sort(my,my+n,comp);
//for(i=0;i<n;++i)cout<<my[i].value<<' '<<my[i].num<<'\12';
int sum=0,k=0;
for(i=0;i<n;++i){
for(j=1;j<=my[i].num;++j){
if(k+1<=v){
k++;
sum+=my[i].value;
}
}
}
cout<<sum<<'\12';
}
return 0;
}
原文:http://blog.csdn.net/zp___waj/article/details/46495011