贪心明显是不可以的吧
by comcopy @ 2022-12-10 18:07:09
确实不可以贪:
```cpp
#include <iostream>
#include <algorithm>
using namespace std;
struct Crystal
{
int volume, power;
int avg;
};
Crystal a[10005];
bool cmp(Crystal a, Crystal b)
{
return a.avg > b.avg;
}
int main()
{
int n, v;
cin >> v >> n;
for (int i = 0; i < n; i++)
{
cin >> a[i].volume >> a[i].power;
a[i].avg = a[i].power/a[i].volume;
}
sort(a, a + n, cmp);
int i = 0, sum = 0;
while (v > 0)
{
int temp=min(a[i].volume,v);
v-=temp;
sum+=temp*a[i].avg;
i++;
}
cout << sum;
return 0;
}
```
by GODTREE @ 2022-12-10 19:52:12