文章
19
粉丝
69
获赞
30
访问
18.1k
#include <bits/stdc++.h>
using namespace std;
typedef struct
{
double w, m;
} water;
bool cmp(water a, water b)
{
return a.m / a.w > b.m / b.w;
}
int main()
{
int n, x;
while (cin >> x >> n)
{
if (x == -1 && n == -1)
{
break;
}
vector<water> waters(n);
auto it = waters.begin();
for (auto it = waters.begin(); it != waters.end(); ++it)
{
cin >> it->m >> it->w;
}
sort(waters.begin(), waters.end(), cmp);
/*
for (auto it = waters.begin(); it != waters.end(); ++it)
{
cout << it->m << " " << it->w << endl;
}
*/
double ans = 0;
for (int i = 0; i < n; i++)
{
if (x >= waters[i].w)
{
ans += waters[i].m;
x -= waters[...
登录后发布评论
暂无评论,来抢沙发