#include <bits/stdc++.h>
int t, m;
int d[105], v[105], f[100005];
int main() {
	std::cin >> t >> m;
	for (int i = 1; i <= m; i++) {
		std::cin >> d[i] >> v[i];
	}
	for (int i = 1; i <= m; i++) {
		for (int j = t; j >= d[i]; j--) {
			f[j] = std::max(f[j], f[j - d[i]] + v[i]);
		}
	}
	std::cout << f[t] << '\n';
	return 0;
}

0 comments

No comments so far...

Information

ID
48
Time
1000ms
Memory
256MiB
Difficulty
2
Tags
# Submissions
44
Accepted
25
Uploaded By