#include #include #include #include #include using namespace std; #define int long long signed main() { int N ,D; cin >> N >> D; int T[2][105]; for (int i = 0; i < N; i++) { cin >> T[0][i] >> T[1][i]; } int dp[2][105]; dp[0][0] = T[0][0]; dp[1][0] = T[1][0] - D; for (int i = 1; i < N; i++) { dp[0][i] = max(dp[0][i - 1] + T[0][i], dp[1][i - 1] + T[0][i] - D); dp[1][i] = max(dp[1][i - 1] + T[1][i], dp[0][i - 1] + T[1][i] - D); } cout << max(dp[0][N - 1], dp[1][N - 1]) << endl; return 0; }