#include #include using namespace std; int main() { int N, D; cin >> N >> D; int T[101], K[101]; int dp[101][2]; for( int i = 1; i <= N; i++ ) { cin >> T[i] >> K[i]; } 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 ); } /* for( int i = 1; i <= N; i++ ) { cout << "i " << i << " T=" << dp[i][0] << " K=" << dp[i][1] << endl; } /**/ cout << max( dp[N][0], dp[N][1] ) << endl; return 0; }