#include #include #include #include using namespace std; typedef long long ll; typedef pair P; const int INF = (int)1e9 + 1; int N; ll D, C[101][2]; ll dp[101][2]; //0:tokyo 1:kyoto int main(void) { cin >> N >> D; for (int i = 0; i < N; i++) { cin >> C[i][0] >> C[i][1]; } for (int i = 0; i <= N; i++) { for (int j = 0; j < 2; j++) { dp[i][j] = -INF; } } dp[0][0] = 0; dp[0][1] = -D; for (int i = 0; i < N; i++) { for (int j = 0; j < 2; j++) { dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + C[i][j]); dp[i + 1][1 - j] = max(dp[i + 1][1 - j], dp[i][j] + C[i][1 - j] - D); } } cout << max(dp[N][0], dp[N][1]) << endl; return 0; }