#include<bits/stdc++.h>
#define N 1005
using namespace std;
int money,n,gs;
struct node{
int jg,sl;
}a[N];
bool cmp(node x,node y){
return x.jg<y.jg;
}
int main(){
cin>>money>>n;
for(int i=1;i<=n;i++){
cin>>a[i].jg>>a[i].sl;
}
sort(a+1,a+n+1,cmp);
for(int i=1;i<=n;i++){
if(a[i].jg*a[i].sl<=money){
gs+=a[i].sl;
money-=a[i].jg*a[i].sl;
}else{
gs+=money/a[i].jg;
cout<<gs;
return 0;
}
}
cout<<gs;
return 0;
}
评论区