#include #include #include #include using namespace std; int main(void) { int n, d, tmp; cin >> n >> d; int *t = new int[n]; int *k = new int[n]; for (int i = 0; i < n; i++) cin >> t[i] >> k[i]; int tsum = t[0]; int ksum = k[0] - d; for (int i = 1; i < n; i++) { tmp = t[i] + max(tsum, ksum - d); ksum = k[i] + max(ksum, tsum - d); tsum = tmp; } cout << max(tsum, ksum) << endl; return 0; }