/* -*- coding: utf-8 -*- * * 1947.cc: No.1947 質より種類数 - yukicoder */ #include #include using namespace std; /* constant */ const int MAX_N = 5000; const int MAX_V = 5000; /* typedef */ typedef long long ll; /* global variables */ ll dp[2][MAX_V + 1]; /* subroutines */ inline void setmax(ll &a, ll b) { if (a < b) a = b; } /* main */ int main() { int n, v, c; scanf("%d%d%d", &n, &v, &c); fill(dp[0], dp[0] + v + 1, -1); dp[0][0] = 0; int cur = 0, nxt = 1; for (int i = 0; i < n; i++) { int vi, wi; scanf("%d%d", &vi, &wi); copy(dp[cur], dp[cur] + v + 1, dp[nxt]); int kv = vi, kw = c + wi; while (kv <= v) { int maxj = v - kv; for (int j = 0; j <= maxj; j++) if (dp[cur][j] >= 0) setmax(dp[nxt][j + kv], dp[cur][j] + kw); kv += vi, kw += wi; } swap(cur, nxt); } ll maxd = 0; for (int j = 0; j <= v; j++) setmax(maxd, dp[cur][j]); printf("%lld\n", maxd); return 0; }