// #pragma GCC optimize("Ofast") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native") #include #define ll long long #define ull unsigned long long #define pii pair #define pp pair,pair> #define pll pair #define pdd pair #define vii vector #define vll vector #define mat vector> #define lb lower_bound #define ub upper_bound #define pb push_back #define fi first #define sc second #define rep(i,n) for(ll i=0;i=0;i--) #define all(x) x.begin(),x.end() #define sz(x) (ll) (x).size() #define pq priority_queue #define pqg priority_queue,greater> #define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin()) #define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin()) #define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end()) #define int ll using namespace std; const ll INF = (1 << 30 ) - 1; const ll LLINF = (1LL << 60LL); const ll MOD = 1000000007; const ll mod = 998244353; const ll MAX = 1100000; const double pi = acos(-1); const double eps = 1e-10; ll dx[4] ={1,0,-1,0} , dy[4] ={0,1,0,-1}; template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } struct Timer{ chrono::system_clock::time_point start, end; Timer(){ start = chrono::system_clock::now(); } ~Timer(){ end = chrono::system_clock::now(); auto msec = chrono::duration_cast(end - start).count(); cerr<<"time : "<>n>>d; ll a[200][3]; rep(i,n){ cin>>a[i][0]>>a[i][1]; } ll dp[200][3]; rep(i,200)rep(j,3) dp[i][j]=0; dp[0][0]=a[0][0]; dp[0][1]=a[0][1]-d; rep2(i,1,n){ rep(j,2){ chmax(dp[i][1-j],dp[i-1][j]+a[i][1-j]-d); chmax(dp[i][j],dp[i-1][j]+a[i][j]); } } cout<