#include<algorithm>
#include<iostream>
using namespace std;
int n,m,money,sum;
struct milk{
int m;
int s;
}a[5000];
bool cmp(milk a,milk b){
if(a.m<b.m)return 1;
else if(a.m==b.m&&a.s>b.s)return 1;
return 0;
}
int main(){
cin>>n>>m;
for(int i=0;i<m;i++)cin>>a[i].m>>a[i].s;
sort(a,a+m,cmp);
for(int i=0;i<m;i++){
if(sum+a[i].s>n){
money+=a[i].m*(n-sum);
break;
}
money+=a[i].s*a[i].m;
sum+=a[i].s;
}
cout<<money;
return 0;
}
P1208 [USACO1.3] 混合牛奶 Mixing Milk
最新推荐文章于 2024-11-18 18:10:05 发布