#include using namespace std; /* ライブラリのincludeはここ。 #include "/home/lolotte/projects/C++_Library/library/xxx.cpp"の様にフルパスで書く。 sourceでvenvに入ってoj-bundle a.cpp -I C++_Library/xxx > bundled.cppで展開される。 */ // clang-format off // --- 型エイリアス (入力の手間を減らす) --- using ll = long long; using vl = vector; using vvl = vector; using vs = vector; using P = pair; // --- 便利マクロ・定数 --- #define int long long #define ALL(a) (a).begin(), (a).end() #define RALL(a) (a).rbegin(), (a).rend() #define el '\n' #define BIT(i, j) (((i) >> (j)) & 1) //bit全探索 // 昇順(小さい順に取り出す):ダイクストラ法など using min_pq = priority_queue, greater>; // 降順(大きい順に取り出す):デフォルト using max_pq = priority_queue; const ll INF = 1LL << 61; const int dx[] = {0, 1, 0, -1}; const int dy[] = {1, 0, -1, 0}; inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << "\n";} inline void No() { cout << "No" << "\n"; } template inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; } // clang-format on signed main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, W; cin >> N >> W; vector w(N), v(N); int best_item_idx = 0; double max_efficiency = -1.0; for (int i = 0; i < N; i++) { cin >> w[i] >> v[i]; double eff = (double)v[i] / w[i]; if (eff > max_efficiency) { max_efficiency = eff; best_item_idx = i; } } ll w_best = w[best_item_idx]; ll v_best = v[best_item_idx]; ll limit = 2000000; vector dp(limit + 1, -1); dp[0] = 0; for (int j = 0; j <= limit; j++) { if (dp[j] == -1) continue; for (int i = 0; i < N; i++) { if (j + w[i] <= limit) { dp[j + w[i]] = max(dp[j + w[i]], dp[j] + v[i]); } } } ll ans = 0; for (ll x = 0; x <= limit; x++) { if (dp[x] == -1) continue; if (x > W) break; ll remaining_capacity = W - x; ll num_best = remaining_capacity / w_best; ll current_value = dp[x] + num_best * v_best; ans = max(ans, current_value); } cout << ans << endl; }