#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 0x3f3f3f3f
struct group{
int p,a;
}t[5009];
bool cmp(group a,group b){
return a.p<b.p;
}
int main(){
int n,m;
cin>>n>>m;
if(n==0){
cout<<"0";
return 0;
}
for(int i=0;i<m;i++)cin>>t[i].p>>t[i].a;
sort(t,t+m,cmp);
int sum=0,ans=0;
for(int i=0;i<m;i++){
if(sum+t[i].a<n)ans+=t[i].a*t[i].p,sum+=t[i].a;
else {
ans+=(n-sum)*t[i].p;
cout<<ans;
return 0;
}
}
return 0;
}
luogu P1208 [USACO1.3]混合牛奶 Mixing Milk
猜你喜欢
转载自blog.csdn.net/Minelois/article/details/113956683
今日推荐
周排行