01背包裸题
#include <iostream>
using namespace std;
const int N = 1010;
int a[N], v[N], f[N];
int main(){
int t, n; cin >> t >> n;
for(int i = 1; i <= n; i ++ ) cin >> a[i] >> v[i];
for(int i = 1; i <= n; i ++ ){
for(int j = t; j > 0; j -- ){
if(a[i] > j) continue;
f[j] = max(f[j], f[j - a[i]] + v[i]);
}
}
cout << f[t] << endl;
return 0;
}