1. #include <iostream>
    2. #include <functional>
    3. using namespace std;
    4. class Solver1 {
    5. static const int MAXN = 1000 + 10;
    6. const int INF = 0X3f3f3f3f;
    7. int v[MAXN], w[MAXN];
    8. int dp[MAXN] = {};
    9. public:
    10. void f() {
    11. int N, V;
    12. cin >> N >> V;
    13. for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];
    14. for (int i = 1; i <= N; i++)
    15. for (int j = v[i]; j <= V; j++)
    16. dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
    17. cout << dp[V] << endl;
    18. }
    19. void f2() {
    20. int N, V;
    21. cin >> N >> V;
    22. for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];
    23. for (int i = 1; i <= N; i++)
    24. for (int j = V; j >= v[i]; j--)
    25. for (int k = 0; k * v[i] <= j; k++)
    26. dp[j] = max(dp[j], dp[j - k * v[i]] + k * w[i]);
    27. cout << dp[V] << endl;
    28. }
    29. void f3() {
    30. int N, V;
    31. cin >> N >> V;
    32. for (int i = 1; i <= N; i++) cin >> v[i] >> w[i];
    33. dp[0] = 0;
    34. for (int i = 1; i <= V; i++) dp[i] = -INF;
    35. for (int i = 1; i <= N; i++)
    36. for (int j = v[i]; j <= V; j++)
    37. dp[j] = max(dp[j], dp[j - v[i]] + w[i]);
    38. cout << *max_element(dp + 1, dp + 1 + V) << endl;
    39. }
    40. };
    41. int main() {
    42. Solver1 s;
    43. s.f3();
    44. }