Language: C++

int main(){
	Int n, W;
	cin >> n >> W;
	std::vector<Int> dp(W + 1);
	RC(i, n){
		Int w, v;
		cin >> w >> v;
		for(Int j = W; j >= w; --j){
			dp[j] = std::max(dp[j], dp[j - w] + v);
		}
	}
	cout << dp[W] << endl;
}
#include <bits/stdc++.h>

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
#define ALL(v) v.begin(), v.end()
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void chmaxmin(T &a, const T &b, const T &(*f)(const T &, const T &)){ a = f(a, b); }
#define chmax(a, b) chmaxmin(a, b, std::max)
#define chmin(a, b) chmaxmin(a, b, std::min)

#if __has_include(<experimental/iterator>)
#include <experimental/iterator>
auto debug = std::experimental::make_ostream_joiner(std::cout, " ");
#endif

/* snippet: inf struct */
#if __cplusplus >= 201703
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::max(); } constexpr auto operator-(); } inf;
struct{ template<class T> constexpr operator T(){ return std::numeric_limits<T>::lowest(); } constexpr auto operator-(); } negative_inf;
constexpr auto decltype(inf)::operator-(){ return negative_inf; }
constexpr auto decltype(negative_inf)::operator-(){ return inf; }
#endif

/* snippet: modint library */
#if __cpp_concepts
template<std::signed_integral T, T MOD>
#else
template<class T, T MOD>
#endif
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val % MOD + (val > 0 ? 0 : MOD)) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* push n numbers and get i-th min */
/* to get min and 2nd min, declare K_th_min<T, 2> and use get<0>(), get<1>() */
#if __cplusplus >= 201703
template<class T, std::size_t K>
class K_th_min{
	friend class K_th_min<T, K + 1>;
	T val;
	K_th_min<T, K - 1> lower;
	void push_(T &x){ lower.push_(x); if(val > x) std::swap(val, x); }
public:
	K_th_min() : val(std::numeric_limits<T>::max()) {}
	void push(T x){ push_(x); }
	template<std::size_t I> T get(){ if constexpr(I == K - 1) return val; else return lower.template get<I>(); }
};
template<class T> class K_th_min<T, 0>{ friend class K_th_min<T, 1>; void push_(T &){} public: K_th_min(){} void push(T){} };
#endif

/* snippet: using declarations */
using Int = long long;
using std::cout;
using std::cin;
using std::endl;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, W;
	cin >> n >> W;
	vector<int> i(W + 1);
	RC(i, n){
		int w, v;
		cin >> w >> v;
		for(int j = W; j >= w; --j){
			i[j] = max(i[j], i[j - w] + v);
		}
	}
	cout << i[W] << endl;
}


Compiler output:
a.cc: In function 'int main()':
a.cc:2:9: error: 'Int' was not declared in this scope; did you mean 'int'?
    2 |         Int n, W;
      |         ^~~
      |         int
a.cc:3:9: error: 'cin' was not declared in this scope
    3 |         cin >> n >> W;
      |         ^~~
a.cc:3:16: error: 'n' was not declared in this scope
    3 |         cin >> n >> W;
      |                ^
a.cc:3:21: error: 'W' was not declared in this scope
    3 |         cin >> n >> W;
      |                     ^
a.cc:4:14: error: 'vector' is not a member of 'std'
    4 |         std::vector<Int> dp(W + 1);
      |              ^~~~~~
a.cc:1:1: note: 'std::vector' is defined in header '<vector>'; this is probably fixable by adding '#include <vector>'
  +++ |+#include <vector>
    1 | int main(){
a.cc:4:26: error: 'dp' was not declared in this scope
    4 |         std::vector<Int> dp(W + 1);
      |                          ^~
a.cc:5:12: error: 'i' was not declared in this scope
    5 |         RC(i, n){
      |            ^
a.cc:5:9: error: 'RC' was not declared in this scope
    5 |         RC(i, n){
      |         ^~
a.cc:5:9: note: the macro 'RC' had not yet been defined
a.cc:18:9: note: it was later defined here
   18 | #define RC(i, n) ARC(i, 0, n)
      |         ^~
a.cc:12:9: error: 'cout' was not declared in this scope
   12 |         cout << dp[W] << endl;
      |         ^~~~
a.cc:12:26: error: 'endl' was not declared in this scope
   12 |         cout << dp[W] << endl;
      |                          ^~~~
a.cc: At global scope:
a.cc:88:5: error: redefinition of 'int main()'
   88 | int main(){
      |     ^~~~
a.cc:1:5: note: 'int main()' previously defined here
    1 | int main(){
      |     ^~~~
a.cc: In function 'int main()':
a.cc:91:9: error: 'vector' was not declared in this scope
   91 |         vector<int> i(W + 1);
      |         ^~~~~~
a.cc:91:9: note: suggested alternatives:
In file included from /usr/include/c++/14/vector:66,
                 from /usr/include/c++/14/functional:64,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:53,
                 from a.cc:14:
/usr/include/c++/14/bits/stl_vector.h:428:11: note:   'std::vector'
  428 |     class vector : protected _Vector_base<_Tp, _Alloc>
      |           ^~~~~~
/usr/include/c++/14/vector:93:13: note:   'std::pmr::vector'
   93 |       using vector = std::vector<_Tp, polymorphic_allocator<_Tp>>;
      |             ^~~~~~
a.cc:91:16: error: expected primary-expression before 'int'
   91 |         vector<int> i(W + 1);
      |                ^~~
a.cc:96:26: error: invalid types 'Int {aka long long int}[int]' for array subscript
   96 |                         i[j] = max(i[j], i[j - w] + v);
      |                          ^
a.cc:96:37: error: invalid types 'Int {aka long long int}[int]' for array subscript
   96 |                         i[j] = max(i[j], i[j - w] + v);
      |                                     ^
a.cc:96:43: error: invalid types 'Int {aka long long int}[int]' for array subscript
   96 |                         i[j] = max(i[j], i[j - w] + v);
      |                                           ^
a.cc:96:32: error: 'max' was not declared in this scope; did you mean 'std::max'?
   96 |                         i[j] = max(i[j], i[j - w] + v);
      |                                ^~~
      |                                std::max
In file included from /usr/include/c++/14/algorithm:61,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51:
/usr/include/c++/14/bits/stl_algo.h:5716:5: note: 'std::max' declared here
 5716 |     max(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
a.cc:99:17: error: 'i' was not declared in this scope
   99 |         cout << i[W] << endl;
      |                 ^