#include #include #include #include using namespace std; int main() { int D; size_t N; cin >> N >> D; vector> TK(N), dp(N); for (auto& x : TK) cin >> x.first >> x.second; dp.at(0).first = TK.at(0).first; dp.at(0).second = TK.at(0).second - D; for (size_t i = 1; i < N; ++i) { dp.at(i).first = max(dp.at(i - 1).second - D, dp.at(i - 1).first) + TK.at(i).first; dp.at(i).second = max(dp.at(i - 1).first - D, dp.at(i - 1).second) + TK.at(i).second; } cout << max(dp.at(N - 1).first, dp.at(N - 1).second); }