#include #include #include #include #include #include #include #include #include #include #include using namespace std; int main(){ long long T, N, x, mx=0; cin >> T >> N; vector c(N), v(N); for (int i=0; i> c[i]; for (int j=0; j> v[j]; for (int i=0; i> dp(N+1, vector(T+1)); for (int i=1; i<=N; i++){ for (int j=0; j<=T; j++){ dp[i][j] = max(dp[i][j], dp[i-1][j]); if (j-c[i-1]>=0) dp[i][j] = max(dp[i][j], dp[i-1][j-c[i-1]]+v[i-1]); } } for (int i=0; i<=T; i++) mx = max(mx, dp[N][i]); cout << mx << endl; return 0; }