给
完全背包模板。
#include <iostream>
#define int long long
using namespace std;
int t, n;
int a[10005];
int b[10005];
int dp[10000005];
signed main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> t >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i] >> b[i];
}
for (int i = 1; i <= n; ++i) {
for (int j = a[i]; j <= t; ++j) {
dp[j] = max(dp[j], dp[j - a[i]] + b[i]);
}
}
cout << dp[t] << endl;
return 0;
}