#pragma GCC target("avx2") #pragma GCC optimize("O3") #pragma GCC optimize("unroll-loops") #include using namespace std; using ll = long long; const int INF = 1e9; const ll inf = 1LL<<60; template bool chmin(T& x, const T& y){ if(x <= y) return false; x = y; return true; } template bool chmax(T& x, const T& y){ if(x >= y) return false; x = y; return true; } void solve() { ll n, V, c; cin >> n >> V >> c; vector> dp(n+1, vector(V+1)); vector v(n), w(n); for (int i=0; i> v[i] >> w[i]; for (int i=0; i= 0) chmax(dp[i+1][j], dp[i][j-v[i]] + w[i] + c); } for (int j=0; j<=V; j++) { if (j - v[i] >= 0) chmax(dp[i+1][j], dp[i+1][j-v[i]] + w[i]); } } cout << *max_element(dp[n].begin(), dp[n].end()) << '\n'; } int main() { ios::sync_with_stdio(false); std::cin.tie(nullptr); // int t; cin >> t; /*while (t--)*/ solve(); }