hduoj_2111

#include <iostream>
#include <vector>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>

using namespace std;

bool cmp(vector<double> a, vector<double> b)
{
	return a[0] > b[0];
}

int main()
{
	vector<vector<double>> t;
	
	vector<double> thing;

	double k;
	double v, n;

	int i;

	double value;

	while (1)
	{
		cin >> v;
		if (0 == v) { break; }
		cin >> n;

		t.clear();
		while (n--)
		{
			thing.clear();
			cin >> k;
			thing.push_back(k);
			cin >> k;
			thing.push_back(k);
			t.push_back(thing);
		}

		// get things
		sort(t.begin(), t.end(), cmp);

		value = 0;
		for (i = 0; i < t.size(); i++)
		{
			if (v > t[i][1])
			{
				v = v - t[i][1];
				value = value + t[i][0] * t[i][1];
			}
			else
			{
				value += v*t[i][0];
				break;
			}
		}
			
		cout << value << endl;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_32862515/article/details/80277928