#define _GLIBCXX_DEBUG #define ll long long #include using namespace std; using Graph = vector>; int main(){ int N, D; cin >> N >> D; int tokyo = 0, kyoto = 0; for(int i = 0; i < N; i++){ int T, K; cin >> T >> K; if(i == 0){ K = max(K-D, 0); } int tokyo2 = max(tokyo + T, kyoto + T - D); int kyoto2 = max(tokyo + K - D, kyoto + K); tokyo = tokyo2, kyoto = kyoto2; // cout << tokyo << " " << kyoto << endl; } cout << max(tokyo, kyoto) << endl; }