#include<bits/stdc++.h>
using namespace std;
struct Milk
{
int p,a;
};
bool cmp_p(Milk tmp1,Milk tmp2)
{
return tmp1.p < tmp2.p;
}
int main()
{
int n,m,sum=0,now=0;
Milk milk[100005] = {};
scanf("%d%d",&n,&m);
for(int i=1;i <= m;i++)
{
scanf("%d %d",&milk[i].p,&milk[i].a);
}
sort(milk+1,milk+1+m,cmp_p);
for(int i=1;i <= m;i++)
{
if(n - now >= milk[i].a)
{
sum += milk[i].a * milk[i].p;
now += milk[i].a;
}
else
{
sum += milk[i].p*(n-now);
now = n;
}
}
printf("%d",sum);
return 0;
}
P1208
于 2023-01-10 15:14:29 首次发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)