#include #include #include #include #include #include #include using namespace std; typedef long long ll; ll N, M; ll A[100000], B[100000]; ll gain[100000][3]; ll dp[100000][3]; const ll INF = 1e18; int main(){ ios::sync_with_stdio(false); cin.tie(0); cout << setprecision(10) << fixed; cin >> N >> M; for(int i = 0; i < N; i++) cin >> A[i] >> B[i]; for(int i = 0; i < N; i++){ gain[i][0] = max(A[i]*M, A[i]*(M-1)+B[i]); gain[i][1] = max(A[i], B[i]); gain[i][2] = 0; // cout << gain[i][0] << ' ' << gain[i][1] << ' ' << gain[i][2] << endl; } dp[0][0] = gain[0][0]; dp[0][1] = gain[0][1]; dp[0][2] = gain[0][2]; for(int i = 1; i < N; i++){ dp[i][0] = dp[i-1][0]+gain[i][0]; dp[i][1] = max({dp[i-1][0]+gain[i][1],dp[i-1][1]+gain[i][1]}); dp[i][2] = max({dp[i-1][0]+gain[i][2],dp[i-1][1]+gain[i][2],dp[i-1][2]+gain[i][2]}); } cout << max({dp[N-1][0], dp[N-1][1], dp[N-1][2]}) << endl; }