Language: C++

#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);

signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, W;
	cin >> N >> W;
	P p[N];
	rep(i,N){
		cin >> p[i].first >> p[i].second;
	}
	sort(p,p+N);
	if(p[0].first > 300){
		int K = W/p[0].first;
		W = W % p[0].first;
		if(K > N){
			int ans = 0;
			rep(i,N){
				ans += p[i].second;
			}
			cout << ans << endl;
			return 0;
		}
		int _ = p[0].first;
		rep(i,N){
			p[i].first -= _;
		}
		int dp[N+1][K+1][500]{};
		rep(i,N){
			rep(j,K+1){
				rep(k,400){
					chmax(dp[i+1][j][k], dp[i][j][k]);
					if(j>0 && k-p[i].first>=0){
						chmax(dp[i+1][j][k], dp[i][j-1][k-p[i].first]+p[i].second);
					}
				}
			}
		}
		cout << dp[N][K][min(W,350)] << endl;
	}
	else{
		W = min(W, N*p[N-1].first);
		int dp[N+1][W+1]{};
		dp[0][0] = 0;
		rep(i,N){
			rep(j,W+1){
				chmax(dp[i+1][j], dp[i][j]);
				if(j-p[i].first>=0){
					chmax(dp[i+1][j], dp[i][j-p[i].first]+p[i].second);
				}
			}
		}
		cout << dp[N][W] << endl;
	}
}

Compiler output:
a.cc: In function 'int main()':
a.cc:51:37: error: no matching function for call to 'min(long long int&, int)'
   51 |                 cout << dp[N][K][min(W,350)] << endl;
      |                                  ~~~^~~~~~~
In file included from /usr/include/c++/14/algorithm:60,
                 from /usr/include/x86_64-linux-gnu/c++/14/bits/stdc++.h:51,
                 from a.cc:1:
/usr/include/c++/14/bits/stl_algobase.h:233:5: note: candidate: 'template<class _Tp> constexpr const _Tp& std::min(const _Tp&, const _Tp&)'
  233 |     min(const _Tp& __a, const _Tp& __b)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:233:5: note:   template argument deduction/substitution failed:
a.cc:51:37: note:   deduced conflicting types for parameter 'const _Tp' ('long long int' and 'int')
   51 |                 cout << dp[N][K][min(W,350)] << endl;
      |                                  ~~~^~~~~~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note: candidate: 'template<class _Tp, class _Compare> constexpr const _Tp& std::min(const _Tp&, const _Tp&, _Compare)'
  281 |     min(const _Tp& __a, const _Tp& __b, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algobase.h:281:5: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/14/algorithm:61:
/usr/include/c++/14/bits/stl_algo.h:5686:5: note: candidate: 'template<class _Tp> constexpr _Tp std::min(initializer_list<_Tp>)'
 5686 |     min(initializer_list<_Tp> __l)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5686:5: note:   candidate expects 1 argument, 2 provided
/usr/include/c++/14/bits/stl_algo.h:5696:5: note: candidate: 'template<class _Tp, class _Compare> constexpr _Tp std::min(initializer_list<_Tp>, _Compare)'
 5696 |     min(initializer_list<_Tp> __l, _Compare __comp)
      |     ^~~
/usr/include/c++/14/bits/stl_algo.h:5696:5: note:   template argument deduction/substitution failed:
a.cc:51:37: note:   mismatched types 'std::initializer_list<_Tp>' and 'long long int'
   51 |                 cout << dp[N][K][min(W,350)] << endl;
      |                                  ~~~^~~~~~~