#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>
#include<iomanip>
using namespace std;
vector<pair<int,int>> v;
bool cmp(pair<int, int> p1, pair<int, int> p2)
{
return (p1.first*1.0 / p1.second) > (p2.first*1.0 / p2.second);
}
double solve(int m, int n)
{
sort(v.begin(), v.end(), cmp);
int i = 0;
double ans = 0;
while (i<n&&m > v[i].second)
{
m -= v[i].second;
ans += v[i].first;
i++;
}
if (i < n&&m>0)
{
ans += m *1.0/ v[i].second*v[i].first;
}
return ans;
}
int main()
{
int m, n;
while (cin >> m >> n&&m != -1)
{
v.clear();
for (int i = 0; i < n; i++)
{
int j, f;
cin >> j>>f;
v.push_back(make_pair(j, f));
}
cout << setiosflags(ios::fixed) << setprecision(3) << solve(m, n) << endl;
}
return 0;
}
hdoj1009_FatMouse' Trade(贪心)
最新推荐文章于 2021-09-02 16:17:36 发布