#include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0; i=b; --i) #define ALL(c) (c).begin(), (c).end() typedef long long ll; typedef vector VI; typedef vector VL; typedef vector VVL; typedef vector VVI; typedef pair P; typedef pair PL; int dp[101][2]; int main() { int n, d; cin >> n >> d; dp[0][1] = -1e9; REP(i,n){ int x, y; cin >> x >> y; dp[i+1][0] = max(dp[i][0], dp[i][1] - d) + x; dp[i+1][1] = max(dp[i][1], dp[i][0] - d) + y; } cout << max(dp[n][0], dp[n][1]) << endl; return 0; }