#include #include using namespace std; int max(const int &a, const int &b) { return a > b ? a : b; } int main() { int day, cost; cin >> day >> cost; int wages[100][2]; for (int i = 0; i < day; i++) { cin >> wages[i][0] >> wages[i][1]; } int tokyo = wages[0][0]; int kyoto = wages[0][1] - cost; for (int i = 1; i < day; i++) { int t = max(tokyo, kyoto - cost) + wages[i][0]; int k = max(tokyo - cost, kyoto) + wages[i][1]; tokyo = t; kyoto = k; } cout << max(tokyo, kyoto) << "\n"; int a; cin >> a; }