#include #include using namespace std; int main() { int n, d; cin >> n >> d; int dp[2][110];//0:tokyo,1:kyoto,j日目iで働く dp[0][0] = 0;dp[1][0] = 0; for (int i = 0;i < n;i++) { int t, k; cin >> t >> k; dp[0][i + 1] = max(dp[0][i], dp[1][i] - d) + t; dp[1][i + 1] = max(dp[0][i] - d, dp[1][i]) + k; } cout << max(dp[0][n], dp[1][n]) << endl; }