/* -*- 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 */ int vs[MAX_N], ws[MAX_N]; ll dp[MAX_V + 1]; /* subroutines */ template inline void setmax(T &a, T b) { if (a < b) a = b; } /* main */ int main() { int n, v, c; scanf("%d%d%d", &n, &v, &c); for (int i = 0; i < n; i++) scanf("%d%d", vs + i, ws + i); fill(dp, dp + v + 1, -1); dp[0] = 0; for (int i = 0; i < n; i++) { int w = c + ws[i]; for (int j = v - vs[i]; j >= 0; j--) if (dp[j] >= 0) setmax(dp[j + vs[i]], dp[j] + w); } for (int j = 0; j <= v; j++) for (int i = 0; i < n; i++) if (j >= vs[i] && dp[j - vs[i]] >= 0) setmax(dp[j], dp[j - vs[i]] + ws[i]); ll maxd = 0; for (int j = 0; j <= v; j++) setmax(maxd, dp[j]); printf("%lld\n", maxd); return 0; }