代码:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define ll long long
#define mes(x,y); memset(x,y,sizeof(x))
#define mv 2147483648+30
using namespace std;
ll gar(ll a,ll b){
return b==0?a:gar(b,a%b);
}
struct node{
int x,y;
}z[30030];
int main(){
ll m,n;
while(cin>>m>>n){
int dp[30030];mes(dp,0);
for(int i=0;i<n;i++){
cin>>z[i].x>>z[i].y;
}
int i,j;
for(i=0;i<n;i++){
for(j=m;j>z[i].x;j--){
dp[j]=max(dp[j],dp[j-z[i].x]+z[i].y*z[i].x);
}
}
cout<<dp[m]<<endl;
}
}