#include #include using namespace std; //#define DISABLE_PRINT #if defined(ENABLE_PRINT) && !defined(DISABLE_PRINT) #define P(...) fprintf(stderr, __VA_ARGS__) #define P2(fmt) fprintf(stderr, fmt) #define LP fprintf(stderr, "L: %d\n", __LINE__) #else #define P(...) ((void)0) #define P2(fmt) ((void)0) #define LP ((void)0) #endif #define rep(i, n) for(int i = 0; i < (int)(n); ++i) #define ALL(x) x.begin(),x.end() using ll = long long; using ull = unsigned long long; int main(int, const char**) { int N, V, C; cin >> N >> V >> C; vector v(N), w(N); rep(i, N) cin >> v[i] >> w[i]; vector dp(V + 1, -1); dp[0] = 0; rep(i, N) { vector t(V + 1, -1); auto cost = v[i]; auto p = w[i] + C; rep(j, V + 1) { if(dp[j] == -1) continue; t[j] = max(t[j], dp[j]); if(j + cost > V) continue; t[j + cost] = max(t[j], dp[j] + p); } swap(dp, t); } vector> dp2(N + 1, vector(V + 1, 0)); rep(i, V + 1) dp2[0][i] = dp[i] == -1 ? 0 : dp[i]; rep(i, N) rep(j, V + 1) { if(j - v[i] < 0) { dp2[i + 1][j] = max(dp2[i + 1][j], dp2[i][j]); } else { dp2[i + 1][j] = max(dp2[i][j], dp2[i + 1][j - v[i]] + w[i]); } } int ans = 0; rep(i, V + 1) ans = max(ans, dp2[N][i]); cout << ans << endl; return 0; }