#include #include #define MAX 100 int n, d, t[MAX], k[MAX], dp[MAX + 1][MAX + 1]; int main(){ scanf("%d %d", &n, &d); for(int i = 0; i < n; i++){ scanf("%d %d", &t[i], &k[i]); } dp[0][0] = t[0], dp[0][1] = k[0] - d; for(int i = 1; i < n; i++){ dp[i][0] = std::max(dp[i - 1][0] + t[i], dp[i - 1][1] + t[i] - d); dp[i][1] = std::max(dp[i - 1][1] + k[i], dp[i - 1][0] + k[i] - d); } printf("%d\n", std::max(dp[n - 1][0], dp[n - 1][1])); return 0; }