#include<iostream> #include<algorithm> using namespace std; int weight[30],cost[30],f[10000]; int money,number; int main(){
cin >> money >> number; for(int i = 1;i <= number;i++){ cin >>cost[i] >>weight[i]; weight[i] *= cost[i]; }
for(int i = 1;i <= number;i++) for(int j = money;j >= cost[i];j--) f[j] = max(f[j],f[j - cost[i]] + weight[i]); cout << f[money] <<endl; return 0; }
|