#include using namespace std; using ll = long long; using pll = pair; #define drep(i, cc, n) for (ll i = (cc); i <= (n); ++i) #define rep(i, n) drep(i, 0, n - 1) #define all(a) (a).begin(), (a).end() #define pb push_back #define fi first #define se second const ll MOD = 1000000007; const ll MOD2 = 998244353; const ll INF = 1LL << 60; const ll MAX_N = 5000; const ll MAX_V = 5000; ll dp[MAX_N][MAX_V][2]; int main(){ ll N, V, C; cin >> N >> V >> C; vector v(N), w(N); rep(i, N) cin >> v[i] >> w[i]; memset(dp, -1, sizeof(dp)); dp[0][0][0] = 0; dp[0][0][1] = 0; for(ll i=1; i<=N; i++){ for(ll j=0; j<=V; j++){ dp[i][j][0] = max(dp[i-1][j][0], dp[i-1][j][1]); if(0 <= j-v[i-1]){ if(dp[i][j-v[i-1]][0] != -1){ dp[i][j][0] = max(dp[i][j][0], dp[i][j-v[i-1]][0]+w[i-1]); } if(dp[i][j-v[i-1]][1] != -1){ dp[i][j][0] = max(dp[i][j][0], dp[i][j-v[i-1]][1]+w[i-1]); } if(dp[i-1][j-v[i-1]][0] != -1){ dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-v[i-1]][0]+C+w[i-1]); } if(dp[i-1][j-v[i-1]][1] != -1){ dp[i][j][1] = max(dp[i][j][1], dp[i-1][j-v[i-1]][1]+C+w[i-1]); } } } } ll ans = -INF; for(ll i=1; i<=N; i++) for(ll j=0; j<=V; j++) ans = max(ans, max(dp[i][j][0], dp[i][j][1])); cout << ans << endl; }