#include int main(void){ int days, koutsu; scanf( "%d %d", &days, &koutsu ); int t[100]; int k[100]; int i = 0; int hikaku[2]; int hikaku_prev[2]; for( i = 0; i < days; i++ ){ int input_t, input_k; scanf( "%d %d", &input_t, &input_k ); t[i] = input_t; k[i] = input_k; } // 初期処理 hikaku_prev[0] = t[0]; hikaku_prev[1] = k[0] - koutsu; hikaku[0] = 0; hikaku[1] = 0; for( i = 1; i < days; i++ ){ //東京の仕事で期待できる最大の値を得る // 移動しない場合と移動した場合 if( hikaku_prev[0] > hikaku_prev[1] - koutsu ){ hikaku[0] = t[i] + hikaku_prev[0]; }else{ hikaku[0] = t[i] + hikaku_prev[1] - koutsu; } //京都の仕事で期待できる最大の値を得る // 移動しない場合と移動した場合 if( hikaku_prev[1] > hikaku_prev[0] - koutsu ){ hikaku[1] = k[i] + hikaku_prev[1]; }else{ hikaku[1] = k[i] + hikaku_prev[0] - koutsu; } //保存 hikaku_prev[0] = hikaku[0]; hikaku_prev[1] = hikaku[1]; } if( hikaku_prev[0] >= hikaku_prev[1] ){ printf( "%d\n", hikaku_prev[0] ); }else{ printf( "%d\n", hikaku_prev[1] ); } return 0; }