Language: C++

using ll = long long;

void max_self(ll& a, ll b) {
    a = max(a, b);
}
void min_self(ll& a, ll b) {
    a = min(a, b);
}

const ll INF = 1e18L + 5;

int main() {
    int n, W;
    scanf("%d%d", &n, &W);
    vector<int> weight(n), value(n);
    for(int i = 0; i < n; ++i) {
        scanf("%d%d", &weight[i], &value[i]);
    }
    int sum_value = 0;
    for(int x : value) {
        sum_value += x;
    }
    vector<ll> dp(sum_value + 1, INF); // 0 ... W
    dp[0] = 0;
    // dp[i] - the minimum total weight of items with total value exactly i
    for(int item = 0; item < n; ++item) {
        for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
        //~ for(int weight_already = 0; weight_already <= W - weight; ++weight_already) {
            min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
        }
    }
    ll answer = 0;
    for(int i = 0; i <= sum_value; ++i) {
        if(dp[i] <= W) {
            answer = max(answer, (ll) i);
        }
        //~ min_self(answer, dp[i]);
    }
    printf("%lld\n", answer);
}


Compiler output:
a.cc: In function 'void max_self(ll&, ll)':
a.cc:4:9: error: 'max' was not declared in this scope
    4 |     a = max(a, b);
      |         ^~~
a.cc: In function 'void min_self(ll&, ll)':
a.cc:7:9: error: 'min' was not declared in this scope
    7 |     a = min(a, b);
      |         ^~~
a.cc: In function 'int main()':
a.cc:14:5: error: 'scanf' was not declared in this scope
   14 |     scanf("%d%d", &n, &W);
      |     ^~~~~
a.cc:15:5: error: 'vector' was not declared in this scope
   15 |     vector<int> weight(n), value(n);
      |     ^~~~~~
a.cc:15:12: error: expected primary-expression before 'int'
   15 |     vector<int> weight(n), value(n);
      |            ^~~
a.cc:17:24: error: 'weight' was not declared in this scope
   17 |         scanf("%d%d", &weight[i], &value[i]);
      |                        ^~~~~~
a.cc:17:36: error: 'value' was not declared in this scope
   17 |         scanf("%d%d", &weight[i], &value[i]);
      |                                    ^~~~~
a.cc:20:17: error: 'value' was not declared in this scope
   20 |     for(int x : value) {
      |                 ^~~~~
a.cc:23:14: error: expected primary-expression before '>' token
   23 |     vector<ll> dp(sum_value + 1, INF); // 0 ... W
      |              ^
a.cc:23:16: error: 'dp' was not declared in this scope
   23 |     vector<ll> dp(sum_value + 1, INF); // 0 ... W
      |                ^~
a.cc:27:45: error: 'value' was not declared in this scope
   27 |         for(int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
      |                                             ^~~~~
a.cc:29:73: error: 'weight' was not declared in this scope
   29 |             min_self(dp[value_already+value[item]], dp[value_already] + weight[item]);
      |                                                                         ^~~~~~
a.cc:35:22: error: 'max' was not declared in this scope
   35 |             answer = max(answer, (ll) i);
      |                      ^~~
a.cc:39:5: error: 'printf' was not declared in this scope
   39 |     printf("%lld\n", answer);
      |     ^~~~~~
a.cc:1:1: note: 'printf' is defined in header '<cstdio>'; this is probably fixable by adding '#include <cstdio>'
  +++ |+#include <cstdio>
    1 | using ll = long long;