#include #include #include #include #include #include using namespace std; #define int long long #define rep(i,n) for(int i = 0; i < (n); i++) #define INF ((long long)1e18) #define MOD ((int)1e9+7) #define endl "\n" #define yn(f) ((f)?"Yes":"No") #define YN(f) ((f)?"YES":"NO") #define MAX 110000 int N, M; int a, b; int A[MAX], B[MAX]; int hoge[MAX][4] = {}; signed main(){ cin.tie(0); ios::sync_with_stdio(false); cout<>N>>M; // hoge[0][0] = -INF; for(int i = 0; i < N; i++){ cin>>a>>b; if(a >= 0 && b >= 0){ if(a >= b) temp = a*M; else temp = a*(M-1)+b; } else if(a >= 0 && b < 0){ temp = a*M; } else if(a < 0 && b >= 0){ temp = b; } else { if(b >= a*M){ temp = b; } else { temp = a*M; } } hoge[i+1][2] += temp+hoge[i][2]; hoge[i+1][1] = max(hoge[i][2],hoge[i][1]) + max(a,b); if(i)hoge[i+1][0] = max(hoge[i][0],max(hoge[i][2],hoge[i][1])); else hoge[i+1][0] = -INF; // cout<