![](https://cdn.luogu.com.cn/upload/pic/8.png)
by cs_zhao @ 2016-12-05 21:42:43
![](https://cdn.luogu.com.cn/upload/pic/7.png)
by cs_zhao @ 2016-12-05 21:43:19
![](https://cdn.luogu.com.cn/upload/pic/14.png)
by cs_zhao @ 2016-12-05 21:43:58
@[cs\_zhao](/space/show?uid=21860) 哥们你在干嘛?
by LYFer @ 2016-12-09 14:40:58
###哈哈哈哈,源程序,上!
```cpp
/*算法思路很简单,贪心,先排序,一直选最便宜的的,直到满足条件*/
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
struct note
{
int x;//单价
int y;//产量
}nm[5003];
int i,j,n,m,pr;
int cmp(struct note a,struct note b) //排序
{
return a.x<b.x;
}
int main()
{
scanf("%d%d",&m,&n);
if(m==0&&n==0)
{
printf("0");
return 0;
}
for(i=1;i<=n;i++)
{
scanf("%d%d",&nm[i].x,&nm[i].y);
}
sort(nm+1,nm+n+1,cmp); //排序
for(i=1;i<=n;i++)
{
if(m>=nm[i].y)
{
pr+=nm[i].y*nm[i].x;
m-=nm[i].y;
}
else
{
pr+=m*nm[i].x;
break;
}
}
printf("%d",pr);
return 0;
}
```
by cs_zhao @ 2016-12-12 21:12:38
对了,我只是玩玩洛谷的图床
玩法:[pic=......]
谢谢合作。
by cs_zhao @ 2016-12-12 21:14:21
![](https://cdn.luogu.com.cn/upload/pic/1001.png)
by 李庚午 @ 2017-01-24 21:16:45