题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2111
题意:中文题(输入可以理解为,物品的单价和物品的总共数量
解析:一共只能拿v个物品,所以从价值最大的开始拿就好,排个序就可以啦
#include <bits/stdc++.h>
using namespace std;
struct node
{
int p,m;
bool operator < (const node &b)const
{
return p>b.p;
}
}a[104];
int main(void)
{
int v,n;
while(~scanf("%d",&v)&&v)
{
scanf("%d",&n);
for(int i=0;i<n;i++)
scanf("%d %d",&a[i].p,&a[i].m);
sort(a,a+n);
int ans = 0;
for(int i=0;i<n;i++)
{
for(int j=0;j<a[i].m;j++)
{
ans += a[i].p;
v--;
if(v==0)
break;
}
if(v==0)
break;
}
printf("%d\n",ans);
}
return 0;
}