#include #include using namespace std; const int tokyo = 0; const int kyoto = 1; int N, D, T, K; int dp[100][2]; int main(void) { cin >> N >> D; cin >> T >> K; dp[0][tokyo] = T; dp[0][kyoto] = K - D; for (int n = 1; n < N; ++n) { cin >> T >> K; dp[n][tokyo] = max(dp[n - 1][tokyo] + T, dp[n - 1][kyoto] + T - D); dp[n][kyoto] = max(dp[n - 1][kyoto] + K, dp[n - 1][tokyo] + K - D); } cout << max(dp[N - 1][tokyo], dp[N - 1][kyoto]) << endl; return 0; }