#include #include #include #include #include #include #include #include #include #include #include #include #include #include #define REP(i, n) for(int i = 0;i < n;i++) #define REPR(i, n) for(int i = n;i >= 0;i--) #define FOR(i, m, n) for(int i = m;i < n;i++) #define FORR(i, m, n) for(int i = m;i >= n;i--) #define SORT(v, n) sort(v, v+n); #define VSORT(v) sort(v.begin(), v.end()); #define llong long long #define pb(a) push_back(a) #define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++) using namespace std; typedef long long int ll; typedef pair pii; typedef pair pll; typedef tuple lltpl; int dy[8] = { 2,2,-2,-2,1,1,-1,-1 }; int dx[8] = { 1,-1,1,-1,2,-2,2,-2 }; /******************************************************************************************/ const int IINF = 1e9 + 7; const ll LINF = 1e18 + 7; const ll MOD = 998244353; template vector make_v(size_t a) { return vector(a); } template auto make_v(size_t a, Ts... ts) { return vector(ts...))>(a, make_v(ts...)); } template typename enable_if::value == 0>::type fill_v(T& t, const V& v) { t = v; } template typename enable_if::value != 0>::type fill_v(T& t, const V& v) { for (auto& e : t) fill_v(e, v); } // vector template istream& operator>>(istream & is, vector & vec) { for (T& x : vec) is >> x; return is; } // pair template ostream& operator<<(ostream & os, pair & pair_var) { os << "(" << pair_var.first << ", " << pair_var.second << ")"; return os; } // vector template ostream& operator<<(ostream & os, const vector & vec) { os << "{"; for (int i = 0; i < vec.size(); i++) { os << vec[i] << (i + 1 == vec.size() ? "" : ", "); }os << "}"; return os; } // map template ostream& operator<<(ostream & os, map & map_var) { os << "{"; repi(itr, map_var) { os << *itr; itr++; if (itr != map_var.end()) os << ", "; itr--; }os << "}"; return os; } // set template ostream& operator<<(ostream & os, set & set_var) { os << "{"; repi(itr, set_var) { os << *itr; itr++; if (itr != set_var.end()) os << ", "; itr--; }os << "}"; return os; } int dp[105][2]; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int N, D; cin >> N >> D; vector T(N), K(N); for (int i = 0; i < N; i++) { cin >> T[i] >> K[i]; } dp[0][1] = 0; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { if (j == 0) { //tokyo dp[i + 1][0] = max(dp[i + 1][0], dp[i][0] + T[i]); //kyoto dp[i + 1][1] = max(dp[i + 1][1], dp[i][0] - D + K[i]); } else { //kyoto if (i == 0)continue; dp[i + 1][1] = max(dp[i + 1][1], dp[i][1] + K[i]); //tokyo dp[i + 1][0] = max(dp[i + 1][0], dp[i][1] - D + T[i]); } } } cout << max(dp[N][0], dp[N][1]) << endl; }