杭电2111

#include
using namespace std;
#include
int n;
double v;
struct bag{
    int weight;
    int price;
};
bag a[105];
int cmp(bag a,bag b)
{
    return a.price>b.price;
}
int main()
{
    while(cin>>v>>n&&n)
    {
        int sum=0;
        for(int i=0;i        {
            cin>>a[i].price>>a[i].weight;
        }
        sort(a,a+n,cmp);
        for(int i=0;i                if(v>0){
            if(v>=a[i].weight)
            {
                sum=sum+a[i].price*a[i].weight;
                v=v-a[i].weight;
            }
            else
                if(v>0&&v            {
                sum=sum+a[i].price*v;
                v=0;
            }
                }
        }
        cout<    }
}

你可能感兴趣的:(杭电2111)