#define _CRT_SECURE_NO_WARNINGS #include #include #include #include #include #include #include #include #include using namespace std; #define REP(i,n) for(int i=0;(i)<(n);(i)++) #define ll long long int dp[102][2]; int main() { int N, D; int T[102], K[102]; cin >> N >> D; REP(i, N) { cin >> T[i + 1] >> K[i + 1]; } //0は東京,1は京都 dp[0][0] = 0; dp[0][1] = -D; for (int i = 1;i <= N;i++) { dp[i][0] = max(dp[i - 1][0] + T[i], dp[i - 1][1] + T[i] - D); dp[i][1] = max(dp[i - 1][1] + K[i], dp[i - 1][0] + K[i] - D); } /* REP(i, N + 1) { cout << dp[i][0] << " " << dp[i][1] << endl; } */ cout << max(dp[N][0],dp[N][1]) << endl; return 0; }