#include using namespace std; using ll = long long; #define rep(i,n) for (int i=0;i<(int)(n);i++) int main(){ ll n,p,c; cin>>n>>p>>c; vector v(n); vector w(n); rep(i,n) cin>>v.at(i)>>w.at(i); vector> dp(2*n+1,vector(p+1,0)); rep(i,n){ rep(j,p){ if(j+v.at(i)<=p) dp.at(i+1).at(j+v.at(i))=max(dp.at(i+1).at(j+v.at(i)),dp.at(i).at(j)+w.at(i)+c); dp.at(i+1).at(j+1)=max(dp.at(i+1).at(j+1),dp.at(i).at(j+1)); } } rep(i,n){ rep(j,p){ if(j+v.at(i)<=p) { dp.at(n+i+1).at(j+v.at(i))=max(dp.at(n+i+1).at(j+v.at(i)),dp.at(n+i).at(j)+w.at(i)); dp.at(n+i).at(j+v.at(i))=max(dp.at(n+i).at(j+v.at(i)),dp.at(n+i).at(j)+w.at(i)); } dp.at(n+i+1).at(j+1)=max(dp.at(n+i+1).at(j+1),dp.at(n+i).at(j+1)); } } /* for(auto dd:dp){ for(auto d:dd) cout<