#include #include #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 rrep(i, n) for (int i = (n) - 1; i >= 0; i--) #define reps(i, n) for (int i = 1; i <= (n); i++) #define repi(i, a, b) for (int i = (a); i < (b); i++) #define all(a) (a).begin(), (a).end() #define bit(b) (1ull << (b)) using namespace std; using i32 = long long; using u32 = unsigned long long; using i64 = long long; using u64 = unsigned long long; using f64 = double; using vi32 = vector; using vu32 = vector; using vi64 = vector; using vu64 = vector; using vf64 = vector; using vstr = vector; using vvi32 = vector; using vvu32 = vector; using vvi64 = vector; using vvu64 = vector; using vvf64 = vector; template void amax(T &x, S y) { if (x < y) x = y; } template void amin(T &x, S y) { if (y < x) x = y; } i64 dp[110][2]; // i日目, j=0:東京,1:京都 class City { public: int t, k; }; int main() { ios::sync_with_stdio(false); cin.tie(0); cout << fixed << setprecision(16); int n, d; cin >> n >> d; dp[0][0] = 0; dp[0][1] = -d; vector cities; rep(i, n) { int t, k; cin >> t >> k; cities.push_back({t, k}); } rep(i, n) { dp[i + 1][0] = max(dp[i][0] + cities[i].t, dp[i][1] + cities[i].k - d); dp[i + 1][1] = max(dp[i][1] + cities[i].k, dp[i][0] + cities[i].t - d); } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }