2022-01-21 03:27:51 +00:00
|
|
|
#include <iostream>
|
2020-10-17 14:10:55 +00:00
|
|
|
|
2022-01-21 03:27:51 +00:00
|
|
|
using std::cin;
|
|
|
|
using std::cout;
|
|
|
|
using std::endl;
|
|
|
|
|
|
|
|
int t, m, v[105], w[105], f[105][105];
|
2020-10-17 14:10:55 +00:00
|
|
|
|
|
|
|
int main() {
|
|
|
|
cin >> t >> m;
|
|
|
|
for (int i = 1; i <= m; i++) {
|
2022-01-21 03:27:51 +00:00
|
|
|
cin >> v[i] >> w[i];
|
2020-10-17 14:10:55 +00:00
|
|
|
}
|
|
|
|
for (int i = 1; i <= m; i++) {
|
|
|
|
for (int j = t; j >= 0; j--) {
|
2022-01-21 03:27:51 +00:00
|
|
|
f[i][j] = f[i - 1][j];
|
|
|
|
if (j >= v[i]) {
|
|
|
|
f[i][j] = std::max(f[i][j], f[i - 1][j - v[i]] + w[i]);
|
2020-10-17 14:10:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-21 03:27:51 +00:00
|
|
|
cout << f[m][t] << endl;
|
2020-10-17 14:10:55 +00:00
|
|
|
return 0;
|
|
|
|
}
|